|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Sorting returns not quite predictable results
Hi All
I thought I was on to a winner there with Svvc's post but we've got slightly different issues I have a file with 4 columns that include a date column I'm trying to sort. Unfortunately, the results aren't quite what I was looking for. This is a sample of the input in the Source file. 09/26/2006,6.2,EUR/ILS,0.085841732 08/01/2006,7.4,GBP/ILS,0.079604097 12/02/2005,4.5,USD/ILS,0.064793205 03/31/2006,4.62,USD/ILS,0.055062438 12/30/2005,4.46,USD/ILS,0.06492932 01/31/2008,5.05,USD/ILS,0.06261755 12/27/2007,4.5,USD/ILS,0.064475983 my sort command is as follows sort -r -u -t '/' -k 3 FILE > FX (I also tested without -r) This almost works except the result provides days that are descending rather than ascending. My result looks like this < 12/30/2005,4.46,USD/ILS,0.06492932 < 12/02/2005,4.5,USD/ILS,0.064793205 < 03/31/2006,4.62,USD/ILS,0.055062438 < 09/26/2006,6.2,EUR/ILS,0.085841732 < 08/01/2006,7.4,GBP/ILS,0.079604097 < 12/27/2007,4.5,USD/ILS,0.064475983 < 01/31/2008,5.05,USD/ILS,0.06261755 as opposed to < 12/02/2005,4.5,USD/ILS,0.064793205 < 12/30/2005,4.46,USD/ILS,0.06492932 < 03/31/2006,4.62,USD/ILS,0.055062438 < 08/01/2006,7.4,GBP/ILS,0.079604097 < 09/26/2006,6.2,EUR/ILS,0.085841732 < 12/27/2007,4.5,USD/ILS,0.064475983 < 01/31/2008,5.05,USD/ILS,0.06261755 Any ideas as always would be greatly appreciated.. Thanks in Advance |
|
#2
|
||||
|
||||
|
Try this out:
Code:
sort -t"/" +2 -n +0 -n +1 -n FILE That'll sort by year, than by month, and finally by day starting with the earliest date available. If you want the dates in the reverse order, starting with he latest date available, just do as follows: Code:
sort -t"/" +2r -n +0r -n +1r -n FILE There might be a less cluttered command line to do this, but that worked for me! |
|
#3
|
||||
|
||||
|
Ugh, just realized a big flaw in the command line I posted above. It's OK, I just forgot to account for the additional numbers after the date. They were screwing the sort up. Try this one instead:
Code:
sort -t"/" -n -k3.1,3.4 -k1 -k2 FILE That'll do the trick. Sorry for the misleading reply above! |
|
#4
|
|||
|
|||
|
Quote:
That did the trick indeed. I had a variation on the sort command you used but that was not quite working. Yours did the trick. Much appreciation.. Thanks |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Sorting returns not quite predictable results |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|