Created
July 12, 2016 15:21
-
-
Save spoterianski/512a1a2695dc3a4d7eb58cca2cea3b2e to your computer and use it in GitHub Desktop.
filter file by keys
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
#!/usr/bin/env python | |
# coding=utf-8 | |
import sys | |
def go(key_filename, filename): | |
k = open(key_filename) | |
keys = list() | |
while 1: | |
lines = k.readlines(100000) | |
if not lines: | |
break | |
for line in lines: | |
val = line.strip() | |
if len(val) != 36: | |
continue | |
keys.append(val) | |
k.close() | |
#print('loaded keys: {0}'.format(len(keys))) | |
f = open(filename) | |
while 1: | |
lines = f.readlines(100000) | |
if not lines: | |
break | |
for line in lines: | |
val = line.strip() | |
if val in keys: | |
print(val) | |
f.close() | |
def main(): | |
if len(sys.argv) < 3: | |
print('usage: ' + sys.argv[0] + ' [keys filename] [filename]') | |
return | |
go(sys.argv[1], sys.argv[2]) | |
if __name__ == '__main__': | |
main() | |
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment