forked from enormandeau/Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathline_extract.py
More file actions
executable file
·35 lines (27 loc) · 826 Bytes
/
line_extract.py
File metadata and controls
executable file
·35 lines (27 loc) · 826 Bytes
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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""Extract lines starting with elements contained in a 'wanted' file.
Wanted file contains one name per line.
Usage:
%program <input_file> <wanted_file> <output_file>"""
import sys
try:
in_file = open(sys.argv[1]) # Input file
wanted_file = sys.argv[2] # Input wanted file, one name per line
out_file = sys.argv[3] # Output file
except:
print __doc__
sys.exit(0)
wanted = set()
with open(wanted_file) as f:
for line in f:
line = line.strip()
if line != "":
wanted.add(line)
lines = [l.strip() for l in in_file.readlines()]
with open(out_file, "w") as f:
for line in lines:
name = line.split("\t")[0]
if name in wanted:
f.write(line + "\n")
#wanted.remove(name)