很难理解如何让python调用系统函数......
the_file = ('logs/consolidated.log.gz')
webstuff = subprocess.Popen(['/usr/bin/zgrep', '/meatsauce/', the_file ],stdout=subprocess.PIPE) % dpt_search
for line in webstuff.stdout:
print line
尝试让python用我的搜索字符串构建另一个文件。
谢谢!
答案 0 :(得分:1)
我推荐Doug Hellmann的PyMotW Subprocess page(引用)“阅读文档,所以你不必”
除此之外:
f = file('sourcefile')
for line in f:
if 'pattern' in line:
# mind the , at the end,
# since there's no stripping involved
# and print adds a newline without it
print line,
除了Python Standard Library documentation for the re module中的文档之外,如果您需要匹配正则表达式,请参阅PyMotW Regular Expression page