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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run Into a Snag with Awk

Status
Not open for further replies.

thunderkid

Technical User
Oct 26, 2000
54
US
I am a novice user of awk. I am at the end of my wit trying to understand what I am doing wrong! I have the following script:

$4 == "rt45"
END { print $0 }

My input file:

seed1 0:01:41.0 2345 rt45
abc 0:01:42.0 2345 rt45
seed1 0:02:03.0 2345 rt45
abc 0:03:04.0 2345 rt45
seed2 0:03:05.0 erte wfe5
nuts 0:03:06.0 erte wfe5
nuts 0:04:07.4 erte wfe5
abc 0:05:08.5 erte wfe5

My output:

seed1 0:01:41.0 2345 rt45
abc 0:01:42.0 2345 rt45
seed1 0:02:03.0 2345 rt45
abc 0:03:04.0 2345 rt45
abc 0:05:08.5 erte wfe5

As I understand awk I should not be getting the last line of my input. I am using the following statement to get it to work:
awk -f myawk data

I have tried variation with printing selected fields, but this script prints out the complete line.

Terry
 
Explanation of your script:
$4 == "rt45"
Print all lines with 4th field='rt45'
END { print $0 }
At the end of the input file, print the last line read so far.

What is the expected result with your example ?


Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
I have found out the solution I was looking for. I needed to use if statement and use proper syntax to get it to print correctly. Here is script that worked for me:

{ if ($4 == "rt45") {
print $1, $2
}

Simple solution. Very simple solution.

With regard,
thunderkid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top