Re: [CentOS] More awk help

2009-06-25 Thread David G . Miller
Joseph L. Casale jcas...@... writes:

 
 Hey guys,
 Looking through my book and the web and I am not having any success
 returning data from a search.
 
 I need to have awk search for a string and print the first field which
 is no problem but now its returning two options as the input data has
 changed. The change is reliable, I only want the first field if it ends
 in a regex that I have, and I only want what that regex matches to be
 printed. Is it possible to do this in a one liner so I don't need to
 construct an awk script?
 
 I suppose I could pipe it into grep and cut but that's not very sexy :)
 
 Any ideas?
 
 Thanks!
 jlc
 

Being an old perl hacker I have to at least suggest doing whatever you're
attempting in perl.  perl gives you much more powerful and flexible regular
expression processing.  It also makes it really simple to pull out whatever
matched within the RE.

Cheers,
Dave


___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] More awk help

2009-06-25 Thread Joseph L. Casale
Being an old perl hacker I have to at least suggest doing whatever you're
attempting in perl.

Yeah I agree but I have found myself needing to duplicate so much work moving
between nix and windows that I resolve to just using UnxTools under windows so
I stay with shell scripting so I can move work back and forth. I don't always
have the luxury of installing Perl in windows.

With the portable vanilla Perl distro coming along that may change! I do know
a smidge of Perl and I love it, its easy to do some great things with.

jlc
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] More awk help

2009-06-25 Thread Les Mikesell
David G. Miller wrote:

 Hey guys,
 Looking through my book and the web and I am not having any success
 returning data from a search.

 I need to have awk search for a string and print the first field which
 is no problem but now its returning two options as the input data has
 changed. The change is reliable, I only want the first field if it ends
 in a regex that I have, and I only want what that regex matches to be
 printed. Is it possible to do this in a one liner so I don't need to
 construct an awk script?

 I suppose I could pipe it into grep and cut but that's not very sexy :)

 Any ideas?

 Thanks!
 jlc

 
 Being an old perl hacker I have to at least suggest doing whatever you're
 attempting in perl.  perl gives you much more powerful and flexible regular
 expression processing.  It also makes it really simple to pull out whatever
 matched within the RE.

This case is probably simple enough for sed, but in general I agree that 
if you need awk you probably might as well use perl which can also 
probably do a better job than the rest of the shell script that is 
likely surrounding this operation.

-- 
   Les Mikesell
lesmikes...@gmail.com

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


[CentOS] More awk help

2009-06-24 Thread Joseph L. Casale
Hey guys,
Looking through my book and the web and I am not having any success
returning data from a search.

I need to have awk search for a string and print the first field which
is no problem but now its returning two options as the input data has
changed. The change is reliable, I only want the first field if it ends
in a regex that I have, and I only want what that regex matches to be
printed. Is it possible to do this in a one liner so I don't need to
construct an awk script?

I suppose I could pipe it into grep and cut but that's not very sexy :)

Any ideas?

Thanks!
jlc
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] More awk help

2009-06-24 Thread Joseph L. Casale
Any ideas?

Sorry, jumped the gun. I search for two strings then use a printf.


___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] More awk help

2009-06-24 Thread Stephen Harris
On Wed, Jun 24, 2009 at 10:31:21PM +, Joseph L. Casale wrote:
 I need to have awk search for a string and print the first field which
 is no problem but now its returning two options as the input data has
 changed. The change is reliable, I only want the first field if it ends
 in a regex that I have, and I only want what that regex matches to be
 printed. Is it possible to do this in a one liner so I don't need to
 construct an awk script?

What you've written is mostly incoherent and incomprehensible.

Free clue: provide examples of input and expected output, including examples
that will _not_ match (so no false positives occur).

I'm not sure if you simply want
  awk '$1 ~ /regexp/ { print $1}'
or something more.

-- 

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


Re: [CentOS] More awk help

2009-06-24 Thread Joseph L. Casale
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
field of a specific match...

Sorry vbg,
jlc
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] More awk help

2009-06-24 Thread Les Mikesell
Joseph L. Casale wrote:
 Hey guys,
 Looking through my book and the web and I am not having any success
 returning data from a search.
 
 I need to have awk search for a string and print the first field which
 is no problem but now its returning two options as the input data has
 changed. The change is reliable, I only want the first field if it ends
 in a regex that I have, and I only want what that regex matches to be
 printed. Is it possible to do this in a one liner so I don't need to
 construct an awk script?
 
 I suppose I could pipe it into grep and cut but that's not very sexy :)

Sed is the next tool up from grep:

sed -n -e 's/.*\(regex\.*)/\1/p'
will print the matching regex, so if you can expand it to match whatever 
you are calling a field it should work.

-- 
   Les Mikesell
lesmiks...@gmail.com

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] More awk help

2009-06-24 Thread Stephen Harris
On Wed, Jun 24, 2009 at 11:15:10PM +, 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@centos.org
http://lists.centos.org/mailman/listinfo/centos