79vsvg
Last Updated: February 25, 2016
·
2.039K
· simonwhitaker

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.

2 Responses
Add your response

1012

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 ·
1013

Simon, nice bio: "Compiled in 1972 with the verbose option enabled." Hehe!

over 1 year ago ·
Filed Under