9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: "Steve Simon" <steve@quintile.net>
To: 9fans@cse.psu.edu
Subject: [9fans] csv files -> embarrasing
Date: Fri, 28 Apr 2006 15:36:11 +0100	[thread overview]
Message-ID: <c22c600f644b0141b2bf9b93b912407e@quintile.net> (raw)

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



             reply	other threads:[~2006-04-28 14:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-28 14:36 Steve Simon [this message]
2006-04-28 14:43 ` quanstro
2006-04-28 16:29 ` Russ Cox
2006-04-28 18:28 ` lucio
2006-04-30 10:36   ` matt
2006-06-01 13:53 ` Victor Nazarov
2006-06-01 16:06   ` rog
2006-06-02  3:09 ` Rogelio Serrano
2006-05-01  0:34 erik quanstrom

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c22c600f644b0141b2bf9b93b912407e@quintile.net \
    --to=steve@quintile.net \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).