4 ms·
Is there a CSV AWK? By that i mean, something that could read the header line in a CSV and automatically generate those variables for each line. Demonstration
by veyron 15y ago
Is there a CSV AWK?
By that i mean, something that could read the header line in a CSV and automatically generate those variables for each line.
Demonstration:
$ cat test.csv
Field1,Field2
1,2
3,4
5,6
$ csvawk '{print Field1+Field2}' test.csv
3
7
11
- klochner 15y agoit would probably be a pretty easy bash script to write
- ralph 15y agoIIRC Aho, Weinberger, and Kernighan's excellent slim tome _The Awk Programming Language_ implements something similar; awk is used to generate the awk with Field1 replaced by $1, etc.
- veyron 15y agoIt's not that simple because you have to properly handle stuff like "blah,blah" which is supposed to be treated as one block (but blindly using awk -F, will give you two separate fields)
- ralph 15y agoWhat's not that simple? I didn't say anything was, just citing a reference. Did you mean to reply to the parent?