Skip to content

Instantly share code, notes, and snippets.

@tapan-p
tapan-p / searchstring.py
Created October 3, 2019 13:54
Search string in file
#File being in same directory as current program
with open('filename.txt') as f:
lines = f.read().splitlines()
print(len(lines))
matching = [s for s in lines if "SearchString" in s] #return the list of lines with SearchString in it
if len(matching)==0:
print "Not found"
else:
print matching