-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatchLinesIn2files.py
More file actions
executable file
·45 lines (35 loc) · 1.05 KB
/
Copy pathmatchLinesIn2files.py
File metadata and controls
executable file
·45 lines (35 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/home/mplace/anaconda3/bin/python
"""
Created on Wed Mar 11 12:29:53 2015
This is a quick and dirty script which compares the first column of 2 files.
Prints out lines that match
@author: mplace
"""
import sys
import re
def main():
if len(sys.argv) == 1:
print("\n\tInput file required.")
print("\trun: matchLineIn2files.py file1 file2")
print("\n")
sys.exit(1)
else:
file1 = sys.argv[1] # smaller file 1 column ex. NC_001133_100000
file2 = sys.argv[2]
found = {}
with open(file1) as f:
for line in f:
line = line.rstrip()
data = line.split()
found[data[0]] = 1
with open(file2) as b:
for line in b:
line = line.rstrip()
item = line.split()
if item[0] in found:
#print(line)
found[item[0]] = line
for k,v in found.items():
print(k, v)
if __name__ == "__main__":
main()