【shell】shuf命令提取文件的随机行

                     【shell】shuf命令提取文件的随机行

shuf命令可以随机提取一个文本文件的不同行,输出到文件或者标准输出中。

shuf

用法: shuf [选项]... [文件]
 或者:  shuf -e [选项]... [参数]...
 或者:  shuf -i LO-HI [选项]...
Write a random permutation of the input lines to standard output.

如果没有指定文件,或者文件为"-",则从标准输入读取。

必选参数对长短选项同时适用。
  -e, --echo                treat each ARG as an input line
  -i, --input-range=LO-HI   treat each number LO through HI as an input line
  -n, --head-count=COUNT    output at most COUNT lines
  -o, --output=FILE         write result to FILE instead of standard output
      --random-source=FILE  get random bytes from FILE
  -r, --repeat              output lines can be repeated
  -z, --zero-terminated     line delimiter is NUL, not newline
      --help        显示此帮助信息并退出
      --version        显示版本信息并退出

例如:提取一个input.txt中的随机20行

shuf input.txt -n 20 -o output.txt

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章