Wednesday 8 July 2015

Grab random lines from a file with Unix

It is very easy to grab a random set of lines from a file using BASH.  There is a built in command called shuf that you can use.

For example,
To extract 1 random line from a file:
shuf -n 1 <file>

To extract 5 random lines from a file:
shuf -n 5 <file>

No comments:

Post a Comment