Created
January 9, 2017 13:36
-
-
Save wieczorek1990/45a2c5dfd6c328362a97b6709be9c524 to your computer and use it in GitHub Desktop.
Random text fetcher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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