我如何使用 Unix 命令行工具按 100 行的块随机排列文件的行?

how can i shuffle the lines of a file by chunks of 100 lines with Unix command line tools?

我有一个很大的文本文件,我想按 100 行的块对文件进行随机排序。因此保留了 100 行的每个块中的顺序。无论如何只用 Unix 命令行工具来完成这个?

是的。首先 split 将输入文件分成 100 行的块,命名为 "foo..."。然后要求 shuf 排列他们的名字。然后cat一起得出结果。

split -l 100 INPUTFILE foo
cat $(/bin/ls foo* | shuf)

您可以通过创建数字 1 到 100 的输入文件来简单地测试一下:

seq 1 100 > inputfile.txt

然后使用 5 行的块。