linux - 在 Linux/Bash 中随机改组行

标签 linux bash shell sh

我在 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 <>;'

关于linux - 在 Linux/Bash 中随机改组行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17578873/

相关文章:

linux - expect 脚本中的 bash 命令重定向因权限被拒绝而失败(spawn ssh user@host 命令 > 输出文件)

bash - ffmpeg遍历目录树,输出到不同根目录下的相同树,只处理一次文件

macos - 如何从 OS X 10.6 的终端检测屏幕是否已锁定或屏幕保护程序是否处于事件状态?

python - 在交互式 shell 中显示函数定义

linux - 最后创建的远程文件上的 Bash cat

linux - 检查 fork() 是否安全

linux - 如何使用 nmcli 连接到隐藏的 wifi 网络

bash - 递归剪切子文件夹中的文件后缀

ios - 不能 telnet gateway.sandbox.push.apple.com 2195?

ruby-on-rails - 执行脚本并在 View 中显示输出/进度 [Ruby/Sinatra(Rails)]