Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: Less greedy...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 21 of 33 Topic 2223 of 2236
Post > Topic >>

Re: Less greedy pattern match

by "Rajan" <svrajan@[EMAIL PROTECTED] > Apr 20, 2008 at 10:21 AM

"Ed Morton" <morton@[EMAIL PROTECTED]
> wrote in message 
news:480B46EC.9080607@[EMAIL PROTECTED]
>
>
> On 4/19/2008 11:15 AM, Cesar Rabak wrote:
>> Ed Morton escreveu:
>>
>>>On 4/18/2008 3:06 PM, pk wrote:
>>><snip>
>>>
>>>>After a bit of tweaking, it seems that the two cases can actually be 
>>>>folded
>>>>into a single body:
>>>>
>>>>{for(i=m+1;i<=NF;i+=2){printf "%s",$i};
>>>> if (NF) {m=(NF%2==m)?1:0}
>>>> if (m==0) print""}
>>>>
>>>>Not elegant as the gawk solution, but at least it should be standard.
>>>>
>>>
>>>At least you got it in one script! Best I could come up with was a
2-pass
>>>approach to turn all the searched-for patterns into a single char 
>>>(control-B in
>>>this case for no particular reason) first and then use that as the RS:
>>>
>>>awk '{$1=$1}1' FS='</?t1>' OFS=^B file | awk 'NR%2' RS=^B ORS=
>>>
>>
>> Notwithstanding, a very elegant solution as it is runnable as one
liner!
>
> This has been a bit of an eye opener for me to the annoyance of 2 
> inconstencies
> in the standard 
> (http://www.opengroup.org/onlinepubs/009695399/utilities/awk.html):
>
> 1) You can have an RE as the FS but not the RS
> 2) You can negate a character in an RE but not a sub-expression in an RE
>
> Obviously GNU awk has solved "1" (thanks to the Arnold et al for that!) 
> but not
> "2" yet....
>
> Does the perl solution posted earlier:
>
>     perl -p0e 's%<t1>.+?</t1>%%gs'
>
> address newlines in between the begin/end pattern and, if so, how (e.g. 
> what
> does it use for the equivalent of RS, and does it allow for the 
> "RS-equivalent"
> to be an RE)?
>
> Ed.
>
Oh! I missed the last question, the best (about gawk), from the command
line 
you can only set it to a character, from the the script you can set it to
a 
"string" not regex! I'm not sure, if you may be able to do that by 
installing some additional packages. Perl experts, fill in.

Rajan




 33 Posts in Topic:
Less greedy pattern match
Prateek <prateek.a@[EM  2008-04-15 19:59:12 
Re: Less greedy pattern match
Ed Morton <morton@[EMA  2008-04-15 22:23:49 
Re: Less greedy pattern match
"Rajan" <svr  2008-04-16 00:02:06 
Re: Less greedy pattern match
pk <pk@[EMAIL PROTECTE  2008-04-17 20:32:10 
Re: Less greedy pattern match
pk <pk@[EMAIL PROTECTE  2008-04-17 21:12:47 
Re: Less greedy pattern match
Ed Morton <morton@[EMA  2008-04-17 14:33:44 
Re: Less greedy pattern match
pk <pk@[EMAIL PROTECTE  2008-04-17 22:01:46 
Re: Less greedy pattern match
pk <pk@[EMAIL PROTECTE  2008-04-17 22:12:04 
Re: Less greedy pattern match
"Rajan" <svr  2008-04-17 19:20:05 
Re: Less greedy pattern match
Ed Morton <morton@[EMA  2008-04-17 23:13:31 
Re: Less greedy pattern match
Ed Morton <morton@[EMA  2008-04-17 23:36:59 
Re: Less greedy pattern match
pk <pk@[EMAIL PROTECTE  2008-04-18 09:50:29 
Re: Less greedy pattern match
Ed Morton <morton@[EMA  2008-04-18 09:27:00 
Re: Less greedy pattern match
pk <pk@[EMAIL PROTECTE  2008-04-18 19:05:23 
Re: Less greedy pattern match
pk <pk@[EMAIL PROTECTE  2008-04-18 19:24:27 
Re: Less greedy pattern match
pk <pk@[EMAIL PROTECTE  2008-04-18 22:06:17 
Re: Less greedy pattern match
Ed Morton <morton@[EMA  2008-04-18 21:19:26 
Re: Less greedy pattern match
Cesar Rabak <csrabak@[  2008-04-19 13:15:05 
Re: Less greedy pattern match
Ed Morton <morton@[EMA  2008-04-20 08:36:44 
Re: Less greedy pattern match
"Rajan" <svr  2008-04-20 09:58:54 
Re: Less greedy pattern match
"Rajan" <svr  2008-04-20 10:21:46 
Re: Less greedy pattern match
Janis Papanagnou <Jani  2008-04-19 18:53:19 
Re: Less greedy pattern match
pk <pk@[EMAIL PROTECTE  2008-04-20 14:32:54 
Re: Less greedy pattern match
Janis Papanagnou <Jani  2008-04-20 16:30:25 
Re: Less greedy pattern match
Ed Morton <morton@[EMA  2008-04-21 09:16:17 
Re: Less greedy pattern match
pk <pk@[EMAIL PROTECTE  2008-04-22 10:09:12 
Re: Less greedy pattern match
Ed Morton <morton@[EMA  2008-04-22 06:14:10 
Re: Less greedy pattern match
"Rajan" <svr  2008-04-18 06:28:14 
Re: Less greedy pattern match
Prateek <prateek.a@[EM  2008-04-15 21:21:23 
Re: Less greedy pattern match
"Rajan" <svr  2008-04-16 00:54:18 
Re: Less greedy pattern match
Ed Morton <morton@[EMA  2008-04-16 07:06:52 
Re: Less greedy pattern match
"Rajan" <svr  2008-04-16 18:01:13 
Re: Less greedy pattern match
Ed Morton <morton@[EMA  2008-04-16 23:48:21 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri May 16 6:19:52 CDT 2008.