From: Victor Nazarov <vir@comtv.ru>
To: Fans of the OS Plan 9 from Bell Labs <9fans@cse.psu.edu>
Subject: Re: [9fans] csv files -> embarrasing
Date: Thu, 1 Jun 2006 17:53:44 +0400 [thread overview]
Message-ID: <447EF168.10209@comtv.ru> (raw)
In-Reply-To: <c22c600f644b0141b2bf9b93b912407e@quintile.net>
Steve Simon 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
>
>
>
>
Thought about this case today. In native Plan9 the solution is quite easy.
Programs share environment and this is the answer:
sed 's/"([^"]*)"/''\1''/g; s/,/ /g' $* |
while (s=`{read}) {
echo 's=('$"s')' | rc
echo $s(1) $s(3) $s(4)
}
next prev parent reply other threads:[~2006-06-01 13:53 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 [this message]
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=447EF168.10209@comtv.ru \
--to=vir@comtv.ru \
--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).