Created
October 3, 2019 13:54
-
-
Save tapan-p/e0a62886f3a5250d6a549c2a8d5ea95a to your computer and use it in GitHub Desktop.
Search string in file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment