一, 多个 txt 文件合并为一个txt 文件
现有 neg_12.txt , part_12.txt , pos_12.txt 三个文件 , 合并为一个名为 train.txt的文件
cat neg_12.txt part_12.txt pos_12.txt > train.txt
就会在目录下生成一个 包含 上面三个文件内容的 train.txt文件。
二 ,随机选取 train.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 显示此帮助信息并退出
--version 显示版本信息并退出
可以根据帮助信息进行操作 ,如随机选取train.txt中的200行保存在新文件 test.txt中
shuf train.txt -n 200 -o test.txt
则在test.txt中为train.txt中随机打乱后的200行数据。