linux怎么随机抽取txt文件的行到新文件
更新:HHH   时间:2023-1-7


今天小编给大家分享一下linux怎么随机抽取txt文件的行到新文件的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。

shuf 随机抽取txt文件的行到新文件

如随机选取train.txt中的200行保存在新文件 test.txt中

shuf train.txt -n 200 -o test.txt

 查看 shuf 命令帮助 “shuf --help”

用法: 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显示此帮助信息并退出

以上就是“linux怎么随机抽取txt文件的行到新文件”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注天达云行业资讯频道。

返回开发技术教程...