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] silly rc quoting question
Date: Mon, 18 Dec 2006 11:33:57 +0000	[thread overview]
Message-ID: <6f978044f0c96ef2c9fb670d2b79d03a@quintile.net> (raw)

I have realised I don't understand rc's quoting
rules as well as I thought I did. I want to parse
the output of a program which has one record per line,
and white space delimited fields in each line.

Some fields have whitespace in them but if they do then
these fields are surrounded in quotes; here I will use cat
and a file as an example, in "real life" its all a
bit more complex.

	term% cat junk
	f1 f2 'free text' f4

I expect when I parse this using the backquote operator then
the quoting would be respected, this appears not to be
the case:

	term% cat junk | while(a=`{read}){
		echo $#a
		echo $a(3)
	}
	5
	'free

Where as I would expect:

	4
	free text

I know I cannot do this with awk (unless I build the parser in awk
(ugh)). Having said this I have been tempted to produce a non-standard,
awk9 which understands plan9's unified quoting rules, even things like

	ls -l | awk '{print $6, $10}'

are not reliable given whitespace in file names.

Is it possible to use rc to parse data using rc's rules?

-Steve


             reply	other threads:[~2006-12-18 11:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-18 11:33 Steve Simon [this message]
2006-12-18 12:05 erik quanstrom
2006-12-18 12:30 erik quanstrom
2006-12-18 15:23 ` Russ Cox

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=6f978044f0c96ef2c9fb670d2b79d03a@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).