Hi,
I have a directory with bunch of subdirectories each subdir has a one file only,
I need to process files only form the subdirectories that have letter “H” in a name.
Each file will contain lines with the words "CELL-1", "CELL-2" up to "CELL-12 "- I’m interested in those lines .
I'd like to scan the file line by line and find/print "CELL-XX" lines for processing that are present in a file and the ones that are missing from a file.
Something like this:
output_file_a.write()
line CELL-1 -missing
line CELL-2 - infile
line CELL-3 -missing
and so on.....
output_file_b.write()
line CELL-1 -infile
line CELL-2 - infile
line CELL-3 -missing
and so on.....
I can find all the files and print out “CELL-xx” lines that are in each file but not the ones that are missing (CELL-xx lines).
Thank you.
I have a directory with bunch of subdirectories each subdir has a one file only,
I need to process files only form the subdirectories that have letter “H” in a name.
Each file will contain lines with the words "CELL-1", "CELL-2" up to "CELL-12 "- I’m interested in those lines .
I'd like to scan the file line by line and find/print "CELL-XX" lines for processing that are present in a file and the ones that are missing from a file.
Something like this:
output_file_a.write()
line CELL-1 -missing
line CELL-2 - infile
line CELL-3 -missing
and so on.....
output_file_b.write()
line CELL-1 -infile
line CELL-2 - infile
line CELL-3 -missing
and so on.....
I can find all the files and print out “CELL-xx” lines that are in each file but not the ones that are missing (CELL-xx lines).
Thank you.
Python:
import os
import pathlib
#path = 'c:/path_tosubdirs/'
mytof = 'H'
for file in os.listdir(path):
hdir_f = os.path.join(path, file)
if mytof in hdir_f : ### Directories with 'H" in name
path2 = hdir_f
for file1 in os.listdir(path2):
hdir_f1 = os.path.join(path2, file1)
print ("DIR\path\file ->>",hdir_f1)
with open (hdir_f1) as cells_file :
for el in cells_file :
if 'CELL-' in el :
el=el.rstrip()
print("CELL-xx ", el)