forked from Te-k/analyst-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsvcut.py
More file actions
25 lines (21 loc) · 890 Bytes
/
csvcut.py
File metadata and controls
25 lines (21 loc) · 890 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
import csv
import argparse
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Cut columns from a CSV file')
parser.add_argument('FILE', help='CSV file')
parser.add_argument('--delimiter', '-d', default=',', help='Delimiter')
parser.add_argument('--quotechar', '-q', default='"', help="Quote char")
parser.add_argument('--cut', '-c', type=int, help="Column to get")
parser.add_argument('--uniq', '-u', action='store_true', help="Only print uniq values")
args = parser.parse_args()
lines = set()
with open(args.FILE) as csvfile:
reader = csv.reader(csvfile, delimiter=args.delimiter, quotechar=args.quotechar)
for row in reader:
if args.uniq:
lines.add(row[args.cut])
else:
print(row[args.cut])
if args.uniq:
for d in lines:
print(d)