|
发表于 2007-3-2 23:07:45
|
显示全部楼层
Post by chunchengfh
如下脚本名为 test.py :
- #!/usr/bin/python
- import sys
- if len(sys.argv) < 2:
- print len(sys.argv)
- print "usage: %s <inputfile> <outputfile>" %sys.argv[0]
- sys.exit()
- input = open(sys.argv[1])
- line = input.readline()
- while line:
- strs = line.split()
- # 若 'depend:' 不在文件末尾,则用:
- # if 'depend:" in strs: 替换下一行:
- if strs[-1] == 'depend:':
- print line,
- line = input.readline()
复制代码
用法为: $ test.py file1 > file2
另:
如果在Linux下则用sed处理会非常简单:
sed -n '/depend:/p' file1 > file2
sed 应该是这样吧:
- sed -n '/depend:\ *$/p' file1 > file2
复制代码 |
|