我有几个操作系统没有排序-R来从我有的txt文件中生成随机列表。例如,我尝试使用以下命令:
sort -R file | head -20000 > newfile我查看了这些操作系统中的手册页,果然没有列出-R选项。
可以从文件生成随机列表并打印到新文件的替代方案是什么?
CentOS 5
发布于 2015-10-08 01:59:24
尝试:
shuf file | head -n 20000 > newfile或者:
cat file | perl -MList::Util=shuffle -e 'print shuffle(<STDIN>);'发布于 2015-10-08 01:59:28
您可以使用shuf命令(如果已安装)。
shuf可以接受一个文件作为其输入
shuf file | head -n 20000 > newfile或从标准输入中读取
cat file | shuf | head -n 20000 > newfile发布于 2015-10-08 03:14:20
cat file | awk 'BEGIN{srand();}{print rand()"\t"$0}' | sort -k1 -n | cut -f2 | head -20000 > newfile这对我很有帮助。
cat ALLEMAILS.txt | awk 'BEGIN{srand();}{print rand()"\t"$0}' | sort -k1 -n | cut -f2 | head -20000 | tee 20000random.txt这是为了看到进展。
https://stackoverflow.com/questions/32999221
复制相似问题