Show a random sample of lines from a text file
Using the king of scripting languages, Perl.
For example, to get a random set of words from /usr/share/dict/words
perl -ne 'print if rand > 0.999' /usr/share/dict/words
With 0.999 you'll get approximately one line out output per thousand lines of input. Tweak accordingly.
Written by Simon Whitaker
Related protips
2 Responses
I like this one, even though it is very slow on large files, because it shuffles the entire file. Shows 15 random lines from file:
cat /usr/share/dict/words | sort -R | tail -15
over 1 year ago
·
Simon, nice bio: "Compiled in 1972 with the verbose option enabled." Hehe!
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Perl
Authors
janosgyerik
25.11K
Jean-Remy Duboc
12.22K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#