【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