user121196 user121196 - 5 months ago 34
Linux Question

Select random lines from a file in bash

in bash script I want to pick out N random lines from input file and output to another file.
how can this be done?

Answer

Sort the file randomly and pick first 100 lines:

$ sort -R input | head -n 100 >output
Comments