python文件全局替换
[root@localhost 1008]# cat test01.txt
1 3194 0 2013-11-15 19:25:47
1 696 0 2013-11-15 19:29:56
1 3194 0 2013-11-15 19:30:09
1 56 0 2013-11-15 19:30:25
1 1111 0 2013-11-15 19:31:41
1 56 0 2013-11-15 19:48:36
1 3160 0 2013-11-15 19:48:43
1 177 0 2013-11-15 19:48:50
1 3438 0 2013-11-15 19:49:02
1 118 0 2013-11-15 19:50:15
1 177 0 2013-11-15 19:50:34
1 3438 0 2013-11-15 19:50:38
#!/usr/bin/python
import fileinput
for line in fileinput.input('/script/Python/1008/test01.txt',inplace=1):
line = line.replace('2013-11-15','zhang')
print line,
1 3194 0 zhangxz 19:25:47
1 696 0 zhangxz 19:29:56
1 3194 0 zhangxz 19:30:09
1 56 0 zhangxz 19:30:25
1 1111 0 zhangxz 19:31:41
1 56 0 zhangxz 19:48:36
1 3160 0 zhangxz 19:48:43
1 177 0 zhangxz 19:48:50
1 3438 0 zhangxz 19:49:02
1 118 0 zhangxz 19:50:15
1 177 0 zhangxz 19:50:34
1 3438 0 zhangxz 19:50:38
相关文章