Skip to content

Instantly share code, notes, and snippets.

@wieczorek1990
Created January 9, 2017 13:36
Show Gist options
  • Save wieczorek1990/45a2c5dfd6c328362a97b6709be9c524 to your computer and use it in GitHub Desktop.
Save wieczorek1990/45a2c5dfd6c328362a97b6709be9c524 to your computer and use it in GitHub Desktop.
Random text fetcher
#!/usr/bin/fish
# Pulls random text from given directory.
set argc (count $argv)
if [ $argc -ne 1 ]
set d (pwd)
else
set d $argv[1]
end
set lrl 16
echo -e "Choosing random $lrl lines from random file in '$d':\n"
cd $d
set fc (find . -type f | wc -l)
set fr (shuf -i 1-$fc -n 1)
set f (find . -type f | sed "$fr"'q;d')
set fl (cat $f | wc -l)
set m (math $fl - 16)
set lrs (shuf -i 1-$m -n 1)
set lre (math $lrs + $lrl)
awk "FNR >= $lrs && FNR <= $lre" $f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment