Sorting on fields for last date


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Sorting on fields for last date
# 1  
Old 07-23-2014
Sorting on fields for last date

Hi all,

I have a file with a list of rpm's that have different dates. I am trying to just grab the latest rpm and install date, and discard the rest. The file has 1000's of entries all with different names and dates.
I have tried sort -k on the file and I am not grabbing the info,

Code:
ftp-0.17-38.el5                      Thu  05  Jun 2014 09:30:28 AM EDT
gail-1.9.2-3.el5                      Mon  27  Aug 2012 03:45:33 PM EDT
gamin-0.1.7-10.el5                 Thu  04  Oct 2012 12:33:51 PM EDT
lgtonode-7.6.2.1-1                 Thu  13  Sep 2012 08:55:42 AM EDT


thanks,
Moderator's Comments:
Mod Comment CODE tags are required when displaying sample input, output, and code segments to preserve spacing between fields and to maintain the distinction between space characters and tab characters.

Last edited by Don Cragun; 07-23-2014 at 02:21 PM.. Reason: Add CODE tags.
# 2  
Old 07-23-2014
Code:
sort -r -k5 -k4M -k3 infile | head -n1

If you're generating this list from a system the following command will list all the installed RPMs by install date starting with the most recent installations:

Code:
rpm -qa --last

# 3  
Old 07-23-2014
Try this:
Code:
sort -k5n -k4M -k3n -k6n file

NB you have different sort criteria, so add n and M as a modifier - not as global options -n -M.
The field 6 worked okay in my test, but might need some fine tuning...
Add | tail -1 to get the latest only.
# 4  
Old 07-23-2014
Hi,

Thanks for the snippet. I did the rpm -qa --last. But I only wanted the latest rpm's. that would show me all rpm's - 2013 - 2012 as well.

appreciate the help..

I think I may be able to work off of the sort command though.
# 5  
Old 07-23-2014
If you don't care about the order, but just want rpms dated 2012, 2013, and 2014, try:
Code:
rpm -qa --last|grep ' 201[234] '

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sorting by date

I am trying to sort by two columns. The first column in an ID, the second is a date in the form yyyy-mm-dd. I need to sort by the ID column, then in ascending order for the date column (earliest date to most recent date compared to today). Input data: 012-abc 2012-04-25 ... (3 Replies)
Discussion started by: mollydog11
3 Replies

2. Shell Programming and Scripting

[Solved] Sorting by several fields

Hello, I have a file with information separated by ";" like this: ABC;20110126000008;00-10-95-29-17-C6;2;37190292 ABC;20110126000008;00-10-95-29-17-C6;1;53140866 ABC;20110126000008;00-10-05-01-11-38;2;11182251 ABC;20110126000008;00-10-05-01-11-38;1;25952816... (3 Replies)
Discussion started by: rubber08
3 Replies

3. Shell Programming and Scripting

AWK multiple line fields sorting

I have a bash script which takes a log file with each record separated by a #. The records have multiple fields but field $1 is always the date and time. When the script is run it prints the record just fine from oldest to newest. I need to have records print out from newest first. Here is the... (7 Replies)
Discussion started by: numele
7 Replies

4. Shell Programming and Scripting

sorting(both Ascending & Descending) files based on multiple fields

Hi All, I am encountered with a problem while sorting a file based on multiple columns . I need to sort like: (field2,ascending) , (field3,ascending) ,(field8,descending) , (field7,ascending),(field13,ascending). So far i was sorting only in ascending order but here i need to use one... (1 Reply)
Discussion started by: apjneeraj
1 Replies

5. UNIX for Dummies Questions & Answers

sorting fields of a line

Hi all, I have a file that looks like this... ########## 1zz2_15-43 1ouy_0-13-35 1.12619901947 2gfs_41-7 1yqj_3 0.793602121208 1bl7_11-3 1wbo_1-3-4 0.791065168287 1ywr_16-3 2ghl_22 0.956896171134 2exc_11-35 1pmq_13-15-87 0.597677672501 2bal_25-7 1ouk_17-19-21-228-58 0.668388304836... (6 Replies)
Discussion started by: Digby
6 Replies

6. UNIX for Dummies Questions & Answers

Sorting 2 positional fields

Hi Friends, I've a large datafile, I've to sort the entire records of this file based on the positions. For ex: ccc112IVEAGH VETERINARY SERVICES cca110SHOOTER PROPERTY SERVICES bbb111JUNIOR GOLF ACADEMY LIMITED aaa110AULD PROPERTIES T/A R&J AULD ccb111LISBURN FUELS aac112P & MRS C... (1 Reply)
Discussion started by: ganapati
1 Replies

7. UNIX for Dummies Questions & Answers

Sorting Compressed Fields

Are any of you guys aware of any problems when trying to sort compressed fields? Why I uncompress the file I am trying to sort, I have no problem sorting but when I try to sort compressed fields it doesnt work properly. I need to be able to sort these compressed fields. Any explanation why? (1 Reply)
Discussion started by: ndoggy020
1 Replies

8. Shell Programming and Scripting

Date Sorting

Hi, I have a list of files that take on the format ABCDE_yymmdd and wish to sort them in ascending date order. I can't use the unix time stamp for the file as this could possibly be different from the date given in the file name. Does anyone know of any way this can be done using unix shell... (14 Replies)
Discussion started by: LiquidChild
14 Replies

9. UNIX for Dummies Questions & Answers

date sorting

Hi at all, I have to sort a log file on timestamp field. That's field is the third! a log file sample..... 1|EVTVOD-1-20060709_000614|2006/07/09-0:11:23|0.3.8 1|EVTVOD-1-20060709_000614|2006/07/09-0:11:16|0.3.8 1|EVTVOD-1-20060709_000614|2006/07/09-0:11:20|0.3.8... (3 Replies)
Discussion started by: nmilella
3 Replies

10. UNIX for Dummies Questions & Answers

sorting on date

I have a file where dates in the form mm/dd/yyyy is the first field. How do I sort the file by the date field? Thanks, Duckman (6 Replies)
Discussion started by: Duckman
6 Replies
Login or Register to Ask a Question