Re:CSVKit: CSV utilities that includes csvsql, csvgrep, csvs...
by icebraining on Tuesday May 27, 2014 @05:10PM
(#7806893)
Grep understands text files, not CSV syntax. They're not equivalent. For example, the following CSV document has two lines, but grep treats them as three:
[ Parent
| on HN ]
Re:CSVKit: CSV utilities that includes csvsql, csvgrep, csvs...
by dbro on Wednesday May 28, 2014 @03:19AM
(#7808804)
That's correct, and as you illustrate it's the possibility to have newlines and commas inside quoted fields that complicates things for grep/awk/cut/etc.
So instead of making a more complex version of tools like grep, we can make the data simple for these tools to understand. That's what https://github.com/dbro/csvquote does. It can be run in a pipeline before the grep stage, and allow grep/cut/awk/... to work with unambiguous field and record delimiters. Then it can restore the newlines and commas inside the quoted fields at the end of the pipeline.