user121196 user121196 - 7 months ago 41
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?


Sort the file randomly and pick first 100 lines:

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