找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 27870|回复: 3

[文本处理] shuf.exe --- 随机排序

[复制链接]
发表于 2013-4-19 00:24:31 | 显示全部楼层 |阅读模式
Usage: shuf.exe [OPTION]... [FILE]
       shuf.exe -e [OPTION]... [ARG]...
       shuf.exe -i LO-HI [OPTION]...

Write a random permutation of the input lines to standard output.

  -e, --echo                treat each ARG as an input line
  -i, --input-range=LO-HI   treat each number LO through HI as an input line
  -n, --head-lines=LINES    output at most LINES lines
  -o, --output=FILE         write result to FILE instead of standard output
      --random-source=FILE  get random bytes from FILE via MD5 hash
                            DEFAULT:  (or not specified) gettimeofday()
  -z, --zero-terminated     end lines with 0 byte, not newline
      --help     display this help and exit
      --version  output version information and exit


----------------------------
官网: http://home.comcast.net/~mjvincent/software/home.html
----------------------------
http://bcn.bathome.net/s/tool/index.html?key=shuf
发表于 2013-4-19 17:08:29 | 显示全部楼层
部分转自 http://www.lampblog.net/ubuntu/shuf%E5%91%BD%E4%BB%A4/

用法:shuf.exe [选项] ... [文件]
       shuf.exe -e [选项] ... [参数] ...
       shuf.exe -i LO-HI [选项] ...

将输入行随机排列输出到标准输出。

-e, --echo            将每个参数视为输入行
-i, --input-range=LO-HI    将LO 到HI 的每个数字视为输入行
-n, --head-count=行数        最多输出指定的行数
-o, --output=文件        将结果输出到指定文件而非标准输出
     --random-source=文件    从指定文件获得随机比特
-z, --zero-terminated    以0 结束行而非新行
     --help        显示此帮助信息并退出
     --version        显示版本信息并退出



应用实例

1、把输入行按随机顺序输出到标准输出
  1. shuf emailfile.txt
复制代码
2、从asciitab.list 文件中随机取出一行数据
  1. shuf -n 1 asciitab.list
复制代码
3、把输入行按随机顺序输出到指定文件
  1. shuf emailfile.txt -o out.txt
复制代码
发表于 2014-7-18 11:20:31 | 显示全部楼层
回复 2# CrLf


    经测试这个版本的shuf.exe -n选项执行不正常
  1. shuf -n5 1.txt -o 2.txt
复制代码
会输出1.txt的全部内容。

@CrLf前辈发的cygwin/bin 中的命令行工具。shuf命令执行正常
http://www.bathome.net/thread-25476-1-1.html
发表于 2014-7-18 15:25:57 | 显示全部楼层
回复 3# elec


    如果不考虑 -n 的话,其实我更喜欢用 gnu sort 7.6 的 -r 选项来乱序
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 05:08 , Processed in 0.017970 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表