[ale] Question about awk

Geoffrey lists at serioustechnology.com
Thu Sep 17 07:36:08 EDT 2009


Chuck Payne wrote:
> Guys,
> 
> 
> Another simple question. I am looking into my mail logs, I just like
> to get the ip that is between []
> 
> athedsl-4487021.home.otenet.gr[94.71.67.117]:
> unknown[187.78.66.100]:
> unknown[192.168.105.11]:
> c-98-224-185-217.hsd1.mi.comcast.net[98.224.185.217]:
> athedsl-333802.home.otenet.gr[85.72.159.136]:
> athedsl-333802.home.otenet.gr[85.72.159.136]:
> pool-151-202-63-204.ny325.east.verizon.net[151.202.63.204]:
> ppp-124-122-183-185.revip2.asianet.co.th[124.122.183.185]:
> unknown[62.68.49.34]:
> 
> 
> Here my search string...
> 
> grep 'Recipient address rejected' mail.log | awk '{ print $10 }'
> 
> 
> I have tried to use sed to remove [] hoping that it would every before
> and after the [] 's, but it ugly.

I'm not sure what you're trying to accomplish.  If you simply want 
what's between the '[]' that's pretty straight forward.  Awk allows you 
to define multiple field delimiters.  In the case of the [], it's a bit 
more problematic in that those characters are special to the flag.  You 
can also rid yourself of the grep as awk has similar functionality:

awk -F '[\\[\\]]' '/Recipient address rejected/ {print $10}'

-- 
Until later, Geoffrey

Those who would give up essential Liberty, to purchase a little
temporary Safety, deserve neither Liberty nor Safety.
  - Benjamin Franklin


More information about the Ale mailing list