[英]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.