diff options
author | Daniel Thompson <daniel.thompson@linaro.org> | 2021-04-21 11:37:49 +0100 |
---|---|---|
committer | Daniel Thompson <daniel.thompson@linaro.org> | 2021-04-21 11:37:49 +0100 |
commit | 864d5fe4d1c2cd6fe491656ab53610600cbf382e (patch) | |
tree | e3c4af55ef27aa0ca453caf29f663d18072e5d3c | |
parent | 171299fe5f3ce3f220cb703cad7cd92fee55b589 (diff) |
csvcat: Simple script to combine CSV files
Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
-rwxr-xr-x | bin/csvcat | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/bin/csvcat b/bin/csvcat new file mode 100755 index 0000000..84d4529 --- /dev/null +++ b/bin/csvcat @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + +# +# csvcat +# +# Concatenate CSV files that have the same column structure. This is +# useful for (typically web based) tools that do not permit comprehensive +# data dumps into a single file. By grabbing data a year at a time and +# concatenating it we are able to generate data files describing a wider +# historic range. +# + +import sys + +header = None + +for fname in sys.argv[1:]: + with open(fname) as f: + this_header = f.readline() + if header and header != this_header: + print('ERROR: mis-matched headers', file=sys.stderr) + sys.exit(1) + if not header: + header = this_header + sys.stdout.write(this_header) + ln = f.readline() + while ln: + sys.stdout.write(ln) + ln = f.readline() + |