[TUHS] Awk for CSV files

Richard Tobin richard at inf.ed.ac.uk
Sun Oct 13 23:53:44 AEST 2019

I was reminded of this by Larry's comment:

> I miss Brian on this list.  I've interacted with him over the years, the
> one I remember the most was I was trying to do an awk like interface to a
> key/value "database".

Recently I've had to deal with a lot of data in CSV
(comma-separated-value) format.  Awk is *almost* prefect for this, but
of course doesn't handle the quoting of fields that contain commas.
One can usually work around it by finding a character that doesn't
occur in the data and converting the CSV file to use that as the
separator, but it's not ideal.

Awk's input could easily be modified to handle CSV files, but output
would be a bit more difficult, because you don't specify field
boundaries explicitly on output.  One possibility would be a printf()
format specifier that takes a field and quotes it appropriately.

-- Richard

The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

More information about the TUHS mailing list