9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: rog@vitanuova.com
To: 9fans@cse.psu.edu
Subject: Re: [9fans] csv files -> embarrasing
Date: Thu,  1 Jun 2006 17:06:28 +0100	[thread overview]
Message-ID: <e0aa13905a775d320025eaa772092b6a@vitanuova.com> (raw)
In-Reply-To: <447EF168.10209@comtv.ru>

> sed 's/"([^"]*)"/''\1''/g; s/,/ /g' $* |
> 	while (s=`{read}) {
> 		echo 's=('$"s')' | rc
> 		echo $s(1) $s(3) $s(4)
>	}

unfortunately this doesn't work, for quite a few reasons.
1) the sed script doesn't deal with quoted double-quotes.
2) nor does it deal with single quotes.
2) the `{read} idiom tokenizes s, ignoring multiple spaces, so
that information is lost when putting them back together with $"s
3) the environment might be shared, but rc caches environment
variables, so the value of $s when passed to the second
echo is the same as that before the rc invocation.

i've also encountered newlines in values in csv files,
which won't help matters.
assuming that there aren't any newlines, an approximation
to a solution might be:

sed -e 's/''/''''/g' -e 's/"(([^"]|"")*)"/''\1''/g' -e 's/""/"/g' -e 's/.*/s=(&)/' |
	ifs='' while(e=`{read}){
		eval $e
		echo $s(1) $s(3) $s(4)
	}

i really don't like using eval in this way though. if you get it wrong,
you've got a nasty loophole.


  reply	other threads:[~2006-06-01 16:06 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 [this message]
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=e0aa13905a775d320025eaa772092b6a@vitanuova.com \
    --to=rog@vitanuova.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).