I have file that contains :
"1 2 3 4 5 5 6 searching new
1 2 3 4 5 5 6 search"
1 2 3 4 5 5 6 search and"
code:
with open('largeFile', 'r') as inF:
for line in inF:
if 'search' in line:
# do_something
I am getting both the lines I want only second line.
You can use Regex.
Use word boundary (\b) to check for
words, and$to check for end of the line..