如何在Unix命令行或shell脚本中随机播放文本文件的行? [英] How can I shuffle the lines of a text file on the Unix command line or in a shell script?

查看:296
本文介绍了如何在Unix命令行或shell脚本中随机播放文本文件的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想随机地随机移动文本文件的行并创建一个新文件。该文件可能有几千行。

I want to shuffle the lines of a text file randomly and create a new file. The file may have several thousands of lines.

如何使用cat,awk,cut等等?

How can I do that with cat, awk, cut, etc.?

推荐答案

您可以使用 shuf 。在一些系统上至少(似乎不是在POSIX)。

You can use shuf. On some systems at least (doesn't appear to be in POSIX).

正如jleedev指出: sort -R 也可能是一个选项。至少在一些系统上;好吧,你得到的图片。 已经指出, sort -R 不会真正随机播放,而是根据它们的哈希值对项进行排序。

As jleedev pointed out: sort -R might also be an option. On some systems at least; well, you get the picture. It has been pointed out that sort -R doesn't really shuffle but instead sort items according to their hash value.

这篇关于如何在Unix命令行或shell脚本中随机播放文本文件的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆