-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreorderCSV.py
More file actions
25 lines (22 loc) · 769 Bytes
/
Copy pathreorderCSV.py
File metadata and controls
25 lines (22 loc) · 769 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
# Reorders CSV and adds an extra column (with the callback value of certificate)
# Usage: python3 reorderCSV.py inputCSV inputHeader certNum outputCSV
# Example use:
# for i in joinedG1/*; do
# certNum=`echo $(basename $i) | sed 's/_1_joined.csv//g'`;
# python3 reorderCSV.py $i commonHeader.csv $certNum reorderedG1/$certNum.csv;
# done
import sys
import csv
inputCSV=sys.argv[1]
inputHeader=sys.argv[2]
certNum=sys.argv[3]
outputCSV=sys.argv[4]
with open(inputHeader) as f: header=list(csv.reader(f))[0]+['CertNum']
with open(inputCSV) as f: data=list(csv.DictReader(f))
with open(outputCSV,'w') as f:
w=csv.DictWriter(f,fieldnames=header)
w.writeheader()
for row in data:
d=dict(row)
d['CertNum']=certNum
w.writerow(d)