在Linux/Bash中随机改组行 [英] Randomly shuffling lines in Linux / Bash
本文介绍了在Linux/Bash中随机改组行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Linux中有一些文件.例如2,我需要将文件改组为一个文件.
I have some files in linux. For example 2 and i need shuffling the files in one file.
例如
$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
后来我重新整理两个文件,我可以得到类似的东西:
And later that i shuffling the two files i can obtain something like:
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一起使用:
Or with Perl :
cat file1 file2 | perl -MList::Util=shuffle -wne 'print shuffle <>;'
这篇关于在Linux/Bash中随机改组行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文