-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcsvcut.py
More file actions
executable file
·27 lines (20 loc) · 774 Bytes
/
csvcut.py
File metadata and controls
executable file
·27 lines (20 loc) · 774 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
#!/usr/bin/env python3
# Cut a csv file base on columns specified in command line arguments
import os
import sys
import argparse
import csv
import re
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Cut a csv file base on columns specified in command line arguments")
parser.add_argument('csv', help='csv file to cut', type=argparse.FileType('r'))
parser.add_argument('startCol', help='start from column')
parser.add_argument('endCol', help='end at column')
args = parser.parse_args()
reader = csv.reader(args.csv)
writer = csv.writer(sys.stdout)
startCol = int(args.startCol) - 1
endCol = int(args.endCol)
for row in reader:
writer.writerow(row[startCol:endCol])
# writer.writerow(row)