From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: From: "Steve Simon" Date: Fri, 28 Apr 2006 15:36:11 +0100 To: 9fans@cse.psu.edu MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Subject: [9fans] csv files -> embarrasing Topicbox-Message-UUID: 4a0f70de-ead1-11e9-9d60-3106f5b1d025 Ok, I have spent half an hour trying to parse CSV files and it's getting embarrasing, I could do it in C but I should be able to use rc + sed + awk. The problem is that some of my CSV files fields contain whitespace and thus have double quotes around them. I thought rc knows about %q quotes strings so I could use it to do my parsing, but it fails, can this be done, or is C the answer? seems a shame to resort to sledge hammers. -Steve cpu% cat file.csv a,b,"c,d,e",f,g p,q,r,s,t cpu% cpu% cat extract #!/bin/rc sed 's/"([^"]*)"/''\1''/g; s/,/ /g' $* | while (s=`{read}) echo $s(1) $s(3) $s(4) cpu% extract file.csv a 'c d p r s