问题
This question already has an answer here:
- What's an easy way to read random line from a file in Unix command line? 13 answers
In a Bash script, I want to pick out N random lines from input file and output to another file.
How can this be done?
回答1:
Use shuf with the -n
option as shown below, to get N
random lines:
shuf -n N input > output
回答2:
Sort the file randomly and pick first 100
lines:
$ sort -R input | head -n 100 >output
来源:https://stackoverflow.com/questions/9245638/select-random-lines-from-a-file