【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

 

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