我在Linux中有一些文件。例如2,我需要将文件改组为一个文件。

例如

$cat file1
line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8


$cat file2
linea one
linea two
linea three
linea four
linea five
linea six
linea seven
linea eight

后来,我重新整理了两个文件,我可以得到类似的东西:
linea eight
line 4
linea five
line 1
linea three
line 8
linea seven
line 5
linea two
linea one
line 2
linea four
line 7
linea six
line 1
line 6

最佳答案

您应该使用shuf命令=)

cat file1 file2 | shuf

或搭配Perl:
cat file1 file2 | perl -MList::Util=shuffle -wne 'print shuffle <>;'

08-05 10:15