当前位置:Linux教程 - Linux资讯 - 乱序排列文件中的所有行

乱序排列文件中的所有行

  [root@www root]# more test.dat 1 --- I 2 --- L 3 --- O 4 --- V 5 --- E 6 --- Y 7 --- O 8 --- U 9 --- ! 10 --- ! [root@www root]# more r.py import sys,random lines = sys.stdin.readlines() olines=[] while lines: olines.append(lines.pop(random.randrange(len(lines)))) sys.stdout.write( "".join(olines)) [root@www root]# cat test.dat python r.py 5 --- E 3 --- O 6 --- Y 10 --- ! 8 --- U 1 --- I 7 --- O 2 --- L 9 --- ! 4 --- V

(出处:http://www.sheup.com)