awk question

 
Thread Tools Search this Thread
# 1  
Old 12-28-2017
awk question

Trying to parse data with three columns. The 2nd and 3rd columns are not constant and there is a data stamp. Tried a few iterations of awk but can't seem to get the desired output.

This is the format:
Code:
entry1 2017-12-12 some_text
entry1 2017-12-13 some_text
entry1 2017-12-18 some_text
entry2 2017-12-10 some_text
entry3 2017-12-08 some_text
entry3 2017-12-04 some_text

This is the desired output (trying to get one entry with the latest date):
Code:
entry1 2017-12-18 some_text
entry2 2017-12-10 some_text
entry3 2017-12-08 some_text

Any help is appreciated.
# 2  
Old 12-28-2017
For unsorted date input, try:-
Code:
sort -k2.1,2.5 -k2.6,2.8 -k2.9,2.11 file | awk 'p&&p!=$1{print v}{p=$1;v=$0}END{print v}'

# 3  
Old 12-28-2017
thank you Yoda, I've never used multiple instances of sort. Happy new year Cheers!
# 4  
Old 12-28-2017
Hmmm - those are not multiple instances of sort but just three sort key definitions - which are not needed, or even can spoil the result. Try simply
Code:
sort file | awk 'p&&p!=$1{print v}{p=$1;v=$0}END{print v}'


|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
awk question desant Shell Programming and Scripting 4 11-29-2016 09:12 AM
awk question bombcan Shell Programming and Scripting 3 09-04-2014 03:59 PM
awk question : system output to awk variable. rveri Shell Programming and Scripting 5 04-23-2013 02:29 AM
awk question JA50 Shell Programming and Scripting 5 04-20-2012 11:04 PM
awk question cabrao Shell Programming and Scripting 4 09-15-2010 10:45 PM
Awk question? momin Shell Programming and Scripting 7 09-14-2010 01:41 AM
'awk' question Shinni Shell Programming and Scripting 4 03-29-2010 09:00 AM
awk $NF question rethink Shell Programming and Scripting 5 02-09-2010 07:42 AM
awk question aoussenko Shell Programming and Scripting 4 06-11-2009 08:23 AM
Basic awk question...getting awk to act on $1 of the command itself JasonHamm UNIX for Dummies Questions & Answers 2 04-02-2009 09:52 AM
awk question jerardfjay Shell Programming and Scripting 2 11-08-2006 08:45 PM
awk question charbel Shell Programming and Scripting 1 10-10-2006 12:03 PM
awk question d__browne Shell Programming and Scripting 34 09-07-2006 03:30 PM
AWK question ucbus Shell Programming and Scripting 1 08-01-2006 03:40 AM
awk question lesstjm Shell Programming and Scripting 3 11-06-2001 01:17 PM