UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 1st, 2006, 09:23 AM
ejazzy ejazzy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 20 ejazzy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 55 m 44 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old March 1st, 2006, 10:49 AM
stanleypane's Avatar
stanleypane stanleypane is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Baltimore, MD
Posts: 208 stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 7 h 4 m 19 sec
Reputation Power: 22
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!

Reply With Quote
  #3  
Old March 1st, 2006, 12:15 PM
stanleypane's Avatar
stanleypane stanleypane is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Baltimore, MD
Posts: 208 stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 7 h 4 m 19 sec
Reputation Power: 22
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!

Reply With Quote
  #4  
Old March 1st, 2006, 12:23 PM
ejazzy ejazzy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 20 ejazzy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 55 m 44 sec
Reputation Power: 0
Quote:
Originally Posted by stanleypane
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!



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

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Sorting returns not quite predictable results


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT