Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Random text fetcher
# Pulls random text from given directory.
set argc (count $argv)
if [ $argc -ne 1 ]
set d (pwd)
set d $argv[1]
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