Skip to content

Instantly share code, notes, and snippets.

@Shitaibin
Last active March 12, 2019 02:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shitaibin/250005593470ce5b5cac2ab9b16718bb to your computer and use it in GitHub Desktop.
Save Shitaibin/250005593470ce5b5cac2ab9b16718bb to your computer and use it in GitHub Desktop.
Grep for big file
# 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