Im trying to search through text files line by line and if a line contains /##/ format, I want to print the line. I know the line I want will have this format because I'm trying to extract the date. Is there syntax for something like this? For example..
if('/%d%d/' in line):
print (line)
Is there something that I can use in between the two forward slashes that is equivalent to a digit 0-9? I have no problem searching the file line by line, here's my code:
items = os.listdir("C:/output3")
for names in items:
if names.endswith(".txt"):
with open('C:/output3/' + names) as currentFile:
for i, line in enumerate(currentFile):
line=line.rstrip()
if('/%d%d/' in line):
print (line)
else:
i = i + 1
Once I can extract the line I can use regex to search for digits in front/behind of the /'s. Thanks.
Aucun commentaire:
Enregistrer un commentaire