From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: From: erik quanstrom Date: Mon, 18 Dec 2006 07:05:00 -0500 To: steve@quintile.net, 9fans@cse.psu.edu Subject: Re: [9fans] silly rc quoting question MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Cc: Topicbox-Message-UUID: f5c7d9de-ead1-11e9-9d60-3106f5b1d025 how about ; eval 'a = (' `{cat junk} ')' ; whatis a a=(f1 f2 'free text' f4) ; echo $#a 4 the reason that your original failed is that /bin/read returns one line at a time. the rc backquote operator then tokenizes not according to rc's syntax rules but by $ifs. the default for $ifs is space, newline, tab. thus the string f1 f2 'free text' f4newline is parsed as "f1", "f2", "'free", "text'", f4 - erik On Mon Dec 18 06:34:41 EST 2006, steve@quintile.net wrote: > 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