繁体   English   中英

Cat,grep并重定向到python

[英]Cat,grep and redirect to python

cat filename | grep "something" >> file2.txt
with open("filename") as origin_file:
    for line in origin_file:
        line = re.findall(r"something",line)

    f=open('file2.txt','w')
    subprocess.call('line',stdout=f)    
    f.close()

这是我尝试过的...不起作用。

我能想到的最简单的解决方案:

with open('filename', 'r') as in_f, open('file2.txt', 'a') as out_f:
    for line in in_f:
        if 'something' in line:
            out_f.write(line)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM