【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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM