ITPub博客

首页 > 应用开发 > IT综合 > 乱序排列文件中的所有行(转)

乱序排列文件中的所有行(转)

原创 IT综合 作者:post0 时间:2007-08-11 15:50:50 0 删除 编辑
乱序排列文件中的所有行(转)[@more@]

[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 ---

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/8225414/viewspace-945961/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    2018
  • 访问量
    8226457