I have a large several hudred thousand lines text file. I have to extract 30,000 specific lines that are all in the text file in random spots. This is the program I have to extr
If the line begins with S0414, then you could use the .startswith
method:
if line.startswith('S0414'): small_file3.write(line)
You could also strip left whitespace, if there is any:
line.lstrip().startswith('S0414')
If 'S0414'
always appears after a certain point, for example, it is always at least 10 characters in and never in the last 5 characters, you could do:
'S0414' in line[10:-5]
Otherwise, you will have to search through each line, like you are.