have different files with same name, in different directories. In these files there are lines which are almost equal, I would like to take out only the last line of these ones( there are more lines after it) and write it in another file.
So far what I have done:
#!/usr/bin/env python
import os
def cd_grep():
for file in os.listdir("."):
if os.path.isfile(file):
for line in open("graph.txt"):
if " 4.49" in line:
line_list=[line]
g = open('comparation','a')
g.write ("%s" % (line[0:4]))
g.close()
os.chdir('4.294')
cd_grep()
os.chdir(os.pardir)
os.chdir('4.394')
cd_grep()
os.chdir(os.pardir)
os.chdir('4.494')
cd_grep()
os.chdir(os.pardir)
os.chdir('4.594')
cd_grep()
os.chdir(os.pardir)
os.chdir('4.694')
cd_grep()
I've created a list because I am gonna take only a specific information of the whole line.
Finally I got that this procedure only works for small files and only if the last line of the file contains the term I'm searching.
For big files, I got this message ( inside the file, which I was hoping to get the line):
Voluntary context switches: 3403
Any idea or suggestion will be very appreciate.