Skip to content

Instantly share code, notes, and snippets.

@sankalp-khare
Created July 22, 2014 08:29
Show Gist options
  • Save sankalp-khare/376edb07b57a18282450 to your computer and use it in GitHub Desktop.
Save sankalp-khare/376edb07b57a18282450 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# Author : Sankalp Khare
# Date : [2014-07-22 Tue]
# the filenames and the query word are hardcoded right now, can be parameterized later as command line arguments
file1="a.txt"
file2="b.txt"
query="this"
def main():
'''read the lines of one file, pick out those that contain a word specified by the user on the commandline, and then output those lines of the second file with the same line numbers'''
with open(file1) as f1, open(file2) as f2:
for linein1,linein2 in zip(f1.readlines(),f2.readlines()):
if query in linein1:
print linein2
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment