[email protected] 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 0 zhangxz 19:30:25
1 1111 0 zhangxz 19:31:41
1 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
This article is from the "Jeff" blog, so be sure to keep this source http://zhangxz.blog.51cto.com/5490116/1561161
Python file Global substitution