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!

Selecting Last Records 2

Status
Not open for further replies.

thunderkid

Technical User
Oct 26, 2000
54
US
How do I use awk to select last record in data below:

23 100 345 F0001
24 400 241 F0002
25 234 213 F0002
30 234 211 F0003
31 212 211 F0003
32 112 211 F0003
26 212 211 F0004

desired format
23 100 345 F0001
25 234 213 F0002
32 112 211 F0003
26 212 211 F0004

Thanks
thunderkid
 
A crude starting point:
awk '{if(NR>1&&f!=$4)print x;f=$4;x=$0}END{print x}' /path/to/input

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,
Works great. Thanks!
Have a star!

thunderkid
 
PHV - would it be possible to explain the logic of this script?

Many thanks
 
The logic of this script is to save the current line on each iteration and to print the last saved line each times the value of $4 changes.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top