随机洗牌在bash文件 [英] randomly shuffling files in bash
本文介绍了随机洗牌在bash文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在linux的一些文件。例如2,我需要在一个文件洗牌的文件。
例如
$ file1的猫
1号线
2号线
3号线
4号线
5号线
6号线
7号线
8号线
和
$ file2的猫
LINEA 1
LINEA 2
LINEA 3
LINEA 4
LINEA 5
LINEA 6
LINEA 7
LINEA 8
和后,我拖着两个文件,我能得到这样的:
LINEA 8
4号线
LINEA 5
1号线
LINEA 3
8号线
LINEA 7
5号线
LINEA 2
LINEA 1
2号线
LINEA 4
7号线
LINEA 6
1号线
6号线
解决方案
您应该使用 SHUF
命令=)
猫文件1文件2 | SHUF
或者用Perl:
猫文件1文件2 | perl的-MList ::的Util =洗牌-wne'打印洗牌<取代;
I have some files in linux. For example 2 and i need shuffling the files in one file.
For example
$cat file1
line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8
and
$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
解决方案
You should use shuf
command =)
cat file1 file2 | shuf
Or with Perl :
cat file1 file2 | perl -MList::Util=shuffle -wne 'print shuffle <>;'
这篇关于随机洗牌在bash文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文