Re: More awk help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



On Wed, Jun 24, 2009 at 11:15:10PM +0000, Joseph L. Casale wrote:
> >What you've written is mostly incoherent and incomprehensible.
> 
> heh, been a long day:)
> 
> Actually I am using gawk "/string1/ && /string2/ { print substr( $1, length($1) - 1, length($1) ) }"
> which gets me what I need, the last two characters of the first

The final parameter to substr() isn't needed  (and would only be "2" for what
you wanted)

> field of a specific match...

Well, it's only printing the first field, not necessarily the field that
matched.
eg
  $ echo hello there everyone | awk '/there/ && /everyone/ { print substr($1,length($1)-1) }'
  lo

You need to do $1 ~ /regex/  if you only want to test against the first field

-- 

rgds
Stephen
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos

[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux