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: matching n'...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 10 of 13 Topic 2216 of 2236
Post > Topic >>

Re: matching n'th pattern...

by pk <pk@[EMAIL PROTECTED] > Apr 6, 2008 at 08:46 PM

pk wrote:

> With the same input format you show, and a bit of extra work:
> 
> $ echo '<html>foo<li>A<br></li><li><b>B</b></li><li>C</li>bar</html>' |
\
> awk -F '</li>' '{for(i=1;i<NF;i++){gsub(/^.*<li>/,"",$i);print $i}}'
> A<br>
> <b>B</b>
> C

Just to be clear, this of course produces a fourth field (not shown above,
since it's not relevant), which you can see by including the NF'th field
in
the loop:

$ echo '<html>foo<li>A<br></li><li><b>B</b></li><li>C</li>bar</html>' | \
awk -F '</li>' '{for(i=1;i<=NF;i++){gsub(/^.*<li>/,"",$i);print $i}}'
A<br>
<b>B</b>
C
bar</html>

-- 
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.




 13 Posts in Topic:
matching n'th pattern...
tomekl <tomek@[EMAIL P  2008-04-06 08:56:07 
Re: matching n'th pattern...
gazelle@[EMAIL PROTECTED]  2008-04-06 16:17:02 
Re: matching n'th pattern...
tomekl <tomek@[EMAIL P  2008-04-06 09:23:23 
Re: matching n'th pattern...
pk <pk@[EMAIL PROTECTE  2008-04-06 19:51:48 
Re: matching n'th pattern...
pk <pk@[EMAIL PROTECTE  2008-04-06 19:56:43 
Re: matching n'th pattern...
tomekl <tomek@[EMAIL P  2008-04-06 09:25:13 
Re: matching n'th pattern...
tomekl <tomek@[EMAIL P  2008-04-06 10:46:07 
Re: matching n'th pattern...
tomekl <tomek@[EMAIL P  2008-04-06 10:50:01 
Re: matching n'th pattern...
pk <pk@[EMAIL PROTECTE  2008-04-06 20:21:09 
Re: matching n'th pattern...
pk <pk@[EMAIL PROTECTE  2008-04-06 20:46:42 
Re: matching n'th pattern...
tom <tomasz.lutelmowsk  2008-04-06 11:49:09 
Re: matching n'th pattern...
Ed Morton <morton@[EMA  2008-04-06 14:06:02 
Re: matching n'th pattern...
Peter Jasper <usenet77  2008-04-08 02:43:47 

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 9:52:55 CDT 2008.