OILS / opy / _regtest / src / tools / csv_concat.py View on Github | oilshell.org

35 lines, 23 significant
1#!/usr/bin/env python
2"""
3csv_concat.py
4"""
5
6import sys
7
8
9def main(argv):
10 first_header = None
11 for path in argv[1:]:
12 with open(path) as f:
13 # Assume there's no quoting or escaping.
14 header = f.readline()
15 if first_header is None:
16 sys.stdout.write(header)
17 first_header = header.strip()
18 else:
19 h = header.strip()
20 if h != first_header:
21 raise RuntimeError(
22 'Invalid header in %r: %r. Expected %r' % (path, h,
23 first_header))
24 # Now print rest of lines
25 for line in f:
26 sys.stdout.write(line)
27
28
29
30if __name__ == '__main__':
31 try:
32 main(sys.argv)
33 except RuntimeError as e:
34 print >>sys.stderr, 'FATAL: %s' % e
35 sys.exit(1)