Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Awk Question on match - select next word

Status
Not open for further replies.

wdellin

MIS
Feb 8, 2002
36
US
I'm hoping someone can help me. I'm trying to awk a file to find a specific word and then pull the next word from the file.

There was an example in February 27, 2003 with the following
example:

awk '{if (match($0,/abcde:/)) print substr($0,RSTART+RLENGTH+1)}' filename

It was entered by someone named CaKiwi.

This is close to what I want but cannot get this to work or see what is wrong.

My version is:

tt50=`awk '{(match($0,/FROM /)) print substr$0,RSTART+RLENGTH+1)}' fix040705.sql`
echo ${tt50}
awk: syntax error near line 1
awk: illegal statement near line 1

Any help appreciated. It's probably a simple thing that
I'm missing.

thanks..




 
Hi:

Problems I See:

1) only works with nawk on solaris
2) missing (
3) needed line split after match on solaris

nawk ' { (match($0,/FROM /))
print substr($0, RSTART + RLENGTH + 1) } ' myfile
 
Lack of if too:
tt50=`awk '{if(match($0,/FROM /)) print substr($0,RSTART+RLENGTH+1)}' fix040705.sql`

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
thanks to olded and PHV for your answers.

olded,
when I tried yours it matched correctly but printed the
matching results with the first line in the file, not by
itself. That part I should be able to work out.

PHV
olded was correct and I changed your awk to nawk on my system and got the correct results.

again thank you both for helping.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top