Sort in fields date and columns. | Unix Linux Forums | UNIX for Advanced & Expert Users

  Go Back    


UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

Sort in fields date and columns.

UNIX for Advanced & Expert Users


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-25-2013
systemoper systemoper is offline
Registered User
 
Join Date: Feb 2011
Last Activity: 21 February 2014, 5:00 PM EST
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Sort in fields date and columns.

Hi colleagues,
I have this output, i need sort for 7th and 8th columns, the column 7th is date mm/dd/yyyy format and column 8th is time hh:mm:ss.number

PRUEBA 1263 0007 1 0 7131292 03/25/2013 16:43:04.159976 PROCESS
PRUEBA1 666 0146 1 0 11600064 03/25/2013 20:35:36.360453 PROCESS
PRUEBA 1232 0002 1 0 6602856 03/21/2013 10:34:04.043798 PROCESS
PRUEBA 1230 0002 1 0 9531456 03/21/2013 10:34:04.012895 PROCESS
PRUEBA 1228 0002 1 0 1769492 03/21/2013 10:34:04.012897 PROCESS
PRUEBA 1191 1270 1 0 5374148 03/25/2013 20:38:30.262300 PROCESS
PRUEBA 1186 0022 1 0 1515770 03/21/2013 10:34:04.214680 PROCESS
PRUEBA 1184 0022 1 0 9023516 03/21/2013 10:34:02.250458 PROCESS
PRUEBA 719 0033 1 0 1007752 03/25/2013 20:35:33.049410 PROCESS
PRUEBA 1142 0007 1 0 11038858 03/24/2013 03:07:52.129286 PROCESS
PRUEBA 1135 0022 1 0 8429658 03/21/2013 10:34:01.686071 PROCESS
PRUEBA 1128 0022 1 0 7278834 03/21/2013 10:34:03.878008 PROCESS
PRUEBA 901 0027 1 0 15548564 03/24/2013 03:08:40.213620 PROCESS
PRUEBA 899 0022 1 0 5456014 03/21/2013 10:33:00.883023 PROCESS
PRUEBA 1218 0023 1 0 15687680 03/24/2013 03:09:57.445248 PROCESS
PRUEBA 1208 1263 1 0 2564242 03/25/2013 20:34:48.322591 PROCESS
PRUEBA 1182 0002 1 0 15323318 03/21/2013 10:34:02.108932 PROCESS
PRUEBA 1179 0002 1 0 6193256 03/21/2013 10:34:02.086872 PROCESS
PRUEBA 1178 0022 1 0 1687770 03/21/2013 10:34:04.139296 PROCESS
PRUEBA 1175 0022 1 0 11354354 03/21/2013 10:34:04.096087 PROCESS
PRUEBA 1172 0022 1 0 15192186 03/21/2013 10:34:02.077381 PROCESS
PRUEBA 1169 0022 1 0 962692 03/21/2013 10:34:02.064175 PROCESS
PRUEBA 1167 1391 1 0 14794986 03/25/2013 20:33:41.071634 PROCESS

The output will be show in this form.
PRUEBA 1191 1270 1 0 5374148 03/25/2013 20:38:30.262300 PROCESS
PRUEBA1 666 0146 1 0 11600064 03/25/2013 20:35:36.360453 PROCESS
PRUEBA 719 0033 1 0 1007752 03/25/2013 20:35:33.049410 PROCESS
PRUEBA 1208 1263 1 0 2564242 03/25/2013 20:34:48.322591 PROCESS
PRUEBA 1167 1391 1 0 14794986 03/25/2013 20:33:41.071634 PROCESS
PRUEBA 1263 0007 1 0 7131292 03/25/2013 16:43:04.159976 PROCESS
PRUEBA 1218 0023 1 0 15687680 03/24/2013 03:09:57.445248 PROCESS
PRUEBA 901 0027 1 0 15548564 03/24/2013 03:08:40.213620 PROCESS
PRUEBA 1142 0007 1 0 11038858 03/24/2013 03:07:52.129286 PROCESS
PRUEBA 1186 0022 1 0 1515770 03/21/2013 10:34:04.214680 PROCESS
PRUEBA 1128 0022 1 0 7278834 03/21/2013 10:34:03.878008 PROCESS
PRUEBA 1184 0022 1 0 9023516 03/21/2013 10:34:02.250458 PROCESS
PRUEBA 1135 0022 1 0 8429658 03/21/2013 10:34:01.686071 PROCESS

thank you for advanced.
Sponsored Links
    #2  
Old 03-25-2013
Don Cragun's Avatar
Don Cragun Don Cragun is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 1 September 2014, 4:56 PM EDT
Location: San Jose, CA, USA
Posts: 4,484
Thanks: 177
Thanked 1,506 Times in 1,278 Posts
I don't understand why your sorted output doesn't contain all of the lines in your unsorted input, but if all you want is to have your data sorted in decreasing order with year, month, day, and time as your sort keys, the following sort command:

Code:
sort -br -k7.7,7 -k7.1,7.2 -k7.4,7.5 -k8,8 -o output input

will put the following data in the file named output :

Code:
PRUEBA 1191 1270 1 0 5374148 03/25/2013 20:38:30.262300 PROCESS
PRUEBA1 666 0146 1 0 11600064 03/25/2013 20:35:36.360453 PROCESS
PRUEBA 719 0033 1 0 1007752 03/25/2013 20:35:33.049410 PROCESS
PRUEBA 1208 1263 1 0 2564242 03/25/2013 20:34:48.322591 PROCESS
PRUEBA 1167 1391 1 0 14794986 03/25/2013 20:33:41.071634 PROCESS
PRUEBA 1263 0007 1 0 7131292 03/25/2013 16:43:04.159976 PROCESS
PRUEBA 1218 0023 1 0 15687680 03/24/2013 03:09:57.445248 PROCESS
PRUEBA 901 0027 1 0 15548564 03/24/2013 03:08:40.213620 PROCESS
PRUEBA 1142 0007 1 0 11038858 03/24/2013 03:07:52.129286 PROCESS
PRUEBA 1186 0022 1 0 1515770 03/21/2013 10:34:04.214680 PROCESS
PRUEBA 1178 0022 1 0 1687770 03/21/2013 10:34:04.139296 PROCESS
PRUEBA 1175 0022 1 0 11354354 03/21/2013 10:34:04.096087 PROCESS
PRUEBA 1232 0002 1 0 6602856 03/21/2013 10:34:04.043798 PROCESS
PRUEBA 1228 0002 1 0 1769492 03/21/2013 10:34:04.012897 PROCESS
PRUEBA 1230 0002 1 0 9531456 03/21/2013 10:34:04.012895 PROCESS
PRUEBA 1128 0022 1 0 7278834 03/21/2013 10:34:03.878008 PROCESS
PRUEBA 1184 0022 1 0 9023516 03/21/2013 10:34:02.250458 PROCESS
PRUEBA 1182 0002 1 0 15323318 03/21/2013 10:34:02.108932 PROCESS
PRUEBA 1179 0002 1 0 6193256 03/21/2013 10:34:02.086872 PROCESS
PRUEBA 1172 0022 1 0 15192186 03/21/2013 10:34:02.077381 PROCESS
PRUEBA 1169 0022 1 0 962692 03/21/2013 10:34:02.064175 PROCESS
PRUEBA 1135 0022 1 0 8429658 03/21/2013 10:34:01.686071 PROCESS
PRUEBA 899 0022 1 0 5456014 03/21/2013 10:33:00.883023 PROCESS

if the data you showed in the first message in this thread is contained in the file named input .
Sponsored Links
Closed 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
Deleting all the fields(columns) from a .csv file if all rows in that columns are blanks ks_reddy Shell Programming and Scripting 4 02-04-2013 04:37 AM
doing a sort on first two fields angel12345 Shell Programming and Scripting 4 07-13-2011 07:25 AM
sort on three fields turquoise_man UNIX for Dummies Questions & Answers 1 08-25-2009 01:01 AM
Sort two columns in a field, one of them being a date sweta_doshi Shell Programming and Scripting 5 07-28-2009 06:15 AM
sort fields edog Shell Programming and Scripting 2 04-15-2002 04:08 PM



All times are GMT -4. The time now is 05:04 PM.