1834009 Members
4366 Online
110063 Solutions
New Discussion

Need sort help?

 
SOLVED
Go to solution
NS_2
Occasional Contributor

Need sort help?

Hi masters,31-may-2002 AND 31-may-2002 01/06/2002 3
30-jun-2002 AND 30-jun-2002 01/07/2002 0
30-jul-2002 AND 31-jul-2002 01/08/2002 2
29-sep-2002 AND 30-sep-2002 01/10/2002 4
01-jun-2002 AND 01-jun-2002 02/06/2002 6
01-jul-2002 AND 01-jul-2002 02/07/2002 0
01-aug-2002 AND 01-aug-2002 02/08/2002 0
01-oct-2002 AND 01-oct-2002 02/10/2002 1
02-jun-2002 AND 02-jun-2002 03/06/2002 0
02-jul-2002 AND 02-jul-2002 03/07/2002 0
02-aug-2002 AND 02-aug-2002 03/08/2002 1
02-oct-2002 AND 02-oct-2002 03/10/2002 0
03-jun-2002 AND 03-jun-2002 04/06/2002 0
03-jul-2002 AND 03-jul-2002 04/07/2002 4

I want to sort 4th field of above file and wants output as below,

31-may-2002 AND 31-may-2002 01/06/2002 3
01-jun-2002 AND 01-jun-2002 02/06/2002 6
02-jun-2002 AND 02-jun-2002 03/06/2002 0
03-jun-2002 AND 03-jun-2002 04/06/2002 0
04-jun-2002 AND 04-jun-2002 05/06/2002 0
01-jul-2002 AND 01-jul-2002 02/07/2002 0
02-jul-2002 AND 02-jul-2002 03/07/2002 0
03-jul-2002 AND 03-jul-2002 04/07/2002 4
04-jul-2002 AND 04-jul-2002 05/07/2002 1
30-jun-2002 AND 30-jun-2002 01/07/2002 0

fourth field sorted by days and months wise.
pl help
POINTS WILL BE GIVEN TO EACH ANSWER.


Take It Easy, Be Happy !
2 REPLIES 2
John Palmer
Honored Contributor
Solution

Re: Need sort help?

Here's a way to do it in a single pipeline...

awk '{print substr($4,7) substr($4,4,2) substr($4,1,2) " " $0}' | sort -nk1 |cut -c10-

Regards,
John
john korterman
Honored Contributor

Re: Need sort help?

Hi,
another suggestion:

# sort -k4.7,4.10 -k4.4,4.5 -k4.1,4.2

regards,
John K.
it would be nice if you always got a second chance