9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: "Rogelio Serrano" <rogelio.serrano@gmail.com>
To: "Fans of the OS Plan 9 from Bell Labs" <9fans@cse.psu.edu>
Subject: Re: [9fans] csv files -> embarrasing
Date: Fri,  2 Jun 2006 11:09:58 +0800	[thread overview]
Message-ID: <a9951d2a0606012009k5c96e47fue275f9a71a3a24e2@mail.gmail.com> (raw)
In-Reply-To: <c22c600f644b0141b2bf9b93b912407e@quintile.net>

On 4/28/06, Steve Simon <steve@quintile.net> wrote:
> 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
>
>

I deal with csv files everyday at work and i just use custom plain c
parsers. Reinventing the wheel and all.

-- 
www.smsglobal.net SMS Global Ltd Short Message Service For Seafarers


  parent reply	other threads:[~2006-06-02  3:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-28 14:36 Steve Simon
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 [this message]
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=a9951d2a0606012009k5c96e47fue275f9a71a3a24e2@mail.gmail.com \
    --to=rogelio.serrano@gmail.com \
    --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).