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()
This is what I've tried...Doesn't work.
Simplest solution I can think of:
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.