awk with CSV files
In AWK, is there any good way to make reference to fields for CSV files?
The difficulties are: 1) Some double-quoted values may contain commas. 2) Some field may be empty. i.e. concatenated commas. e.g. Code:
1,"Good Work, Ltd.",,1.3, Code:
FS = "," How do you work around to process CSVs with such trouble? Thanks. |
Hi, I use awk to get my bandwidth usage from my Broadband isp.
I need to extract field 4, and then remove non-numerical chars. I hope this link helps you figure it out for your situation. $n depicts column number http://www.ibm.com/developerworks/ai.../section5.html My script looks like this... I'm no expert, but I hope this helps. Code:
#!/bin/bash http://www.ibm.com/developerworks/ai.../section5.html Regards Glenn |
There is a good description of the CSV format (actually formats -- thee is no standard) here.
As well as the difficulties described in the OP, CSV files may include newlines in fields -- tricky for line-orientated awk -- and may not populate empty fields at the end of the record. Here's the input part of an awk script that can cope with both of those situations; it was written to parse an Outlook Contacts CSV: Code:
#!/usr/bin/awk -f |
I did something like this:
Code:
{ |
I was along the same lines as only fixing the double quote scenario:
Code:
#!/usr/bin/awk -f |
And another alternative similar to your own:
Code:
#!/usr/bin/awk -f |
All times are GMT -5. The time now is 09:20 PM. |