- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: !! How to compare between these two lines and ...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-08-2009 01:51 PM
тАО04-08-2009 01:51 PM
# SSort UNIX 10/14/2005 10/13/2010 "tox" "9000/800" 16 * * * V849-6-1
# SSort UNIX 11/31/1996 11/02/2010 "tox" "9000/800" 16 * * * W237-S-2
I have a text file with two or multiple values like this and what I am trying to do is compare these lines and just keep the line with the latest date on it.
Note: every line have two dates but the one we have to look at is the second date
10/13/2010 in first line and 11/02/2010
in second line.
Any way to do it using unix commands?
I can compare two dates with this command and print the required one
if the file name is tmp I can do this and get the latest date
cat tmp|awk '{print $5}'|sort -t '|' -k3n -k1n -k2n|sed '$!d'
but what I want is the entire line like this
# SSort UNIX 11/31/1996 11/02/2010 "tox" "9000/800" 16 * * * W237-S-2
not only date value.
could anyone help me how can I do it.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-08-2009 02:12 PM
- Tags:
- Sort
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-08-2009 02:17 PM
тАО04-08-2009 02:17 PM
Re: !! How to compare between these two lines and get the latest one!!
If you have multiple pairs of lines you could use 'awk' to read two lines at a time' split the line into its component fields; rejoin the date in a YYYYMMDD order and compare the records, printing the "larger" date.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-08-2009 02:22 PM
тАО04-08-2009 02:22 PM
Re: !! How to compare between these two lines and get the latest one!!
# SSort UNIX 10/14/2005 10/13/2010 "tox" "9000/800" 16 * * * V849-6-1
# SSort UNIX 11/31/1996 11/02/2010 "tox" "9000/800" 16 * * * W237-S-2
when I run your command i got this output
# SSort UNIX 12/14/2005 10/13/2010 "tox" "9000/800" 16 * * * V849-6-1
which is not right.
You are right I want the line with the latest date but the other one is latest
# SSort UNIX 11/31/1996 11/02/2010 "tox" "9000/800" 16 * * * W237-S-2
Note: I need to compare the second date field not the first
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-08-2009 02:54 PM
тАО04-08-2009 02:54 PM
Re: !! How to compare between these two lines and get the latest one!!
Dennis inadvertantly reversed the order of the sort. You want"
# sort -r -k5.7,5.10 -k5.1,5.2 -k5.4,5.5 tmp|head -1
...which sorts on the second date's year, then month, then day.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-08-2009 03:11 PM
тАО04-08-2009 03:11 PM
Re: !! How to compare between these two lines and get the latest one!!
Oops, wrong field order. It would work for Europe. :-)
That's why dates should always be YYYY/MM/DD so you can sort on the whole field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-09-2009 08:39 AM
тАО04-09-2009 08:39 AM
Re: !! How to compare between these two lines and get the latest one!!
Dennis you are right that would have worked in Europe but anyway its working in states too now heheh.
The solution Dennis gave was right but he just did it opposite which was corrected by james.
I appreciate the help
Cheers!!!