Last active
March 12, 2019 02:50
-
-
Save Shitaibin/250005593470ce5b5cac2ab9b16718bb to your computer and use it in GitHub Desktop.
Grep for big file
This file contains hidden or 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
# I found grep is very slow for big files, I made a simpe python version | |
import sys | |
def search(file_name, wants): | |
with open(file_name, 'r') as file: | |
for line in file: | |
for w in wants: | |
if w in line: | |
print line, | |
def main(): | |
if len(sys.argv) < 3: | |
print "Usage: python py_grep.py file_name.log \"string1\" \"string2\" ..." | |
return | |
file_name = sys.argv[1] | |
wants = sys.argv[2:] | |
search(file_name, wants) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment