Home Man
Search
Today's Posts
Register

If you're not sure where to post a Unix or Linux question, post it here. All unix and Linux beginners welcome in this forum!

awk question

Login to Reply

 
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}'

Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Question about awk Homa Shell Programming and Scripting 2 06-14-2013 11:45 AM
awk question greycells Shell Programming and Scripting 9 05-10-2013 04:38 AM
awk question ctsgnb Shell Programming and Scripting 6 01-27-2011 09:38 AM
sed question svajhala Shell Programming and Scripting 17 12-28-2010 04:20 PM
sed question stumpyuk Shell Programming and Scripting 3 11-24-2010 05:24 AM
sed question huko99 Shell Programming and Scripting 5 11-19-2010 11:57 PM
ssh question ij_2005 Security 2 06-24-2008 12:23 AM
ssh question mcraul UNIX for Dummies Questions & Answers 12 06-10-2008 02:59 PM
Another sed question STiVo Shell Programming and Scripting 1 06-15-2005 02:47 PM


All times are GMT -4. The time now is 02:18 AM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password