从文件中选择随机行 [英] Select random lines from a file

查看:94
本文介绍了从文件中选择随机行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Bash脚本中,我想从输入文件中提取N条随机行并输出到另一个文件.

In a Bash script, I want to pick out N random lines from input file and output to another file.

这怎么办?

推荐答案

shuf -n选项,如下所示,以获得N随机行:

Use shuf with the -n option as shown below, to get N random lines:

shuf -n N input > output

这篇关于从文件中选择随机行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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