sorting

I'm having a problem sorting. The sort seems to work as excepted on the first and second fieldspec but the thrid fieldspec (month and day) is not always working. Here's a sample input line and the sort command I'm using:

NBU_preview_out contains lines of the follow format:

11/13/2006 02:02:12 RobinPolicy RobinIncr robin_1163404932 honeydew 000167 2 1 000124

sort -o $NBU_preview_out -k 7 -k 1.7,1.10 -k 1.1,1.5 -k 2 -k 5-k 9 $NBU_preview_out

any ideas?

Thanks,

Glen Gunselman

[523 byte] By [sysglen] at [2007-11-26 11:32:49]
# 1
Did you mean to use the same environment variable's value to define both the output and input file?Please provide a few more lines of input for testing.John
sun_powered at 2007-7-7 3:48:36 > top of Java-index,Solaris Operating System,Solaris Essentials - General Technical Questions...
# 2
What does the file look like for days before 10 and months before 10.Less digits? Leading zero? Leading space?
robertcohen at 2007-7-7 3:48:36 > top of Java-index,Solaris Operating System,Solaris Essentials - General Technical Questions...
# 3

Here's a few more input lines:

07/29/2006 00:02:22 ELearningPolicy ELearningMonthly elearning_1154149342 honeydew 000157 1 1

07/28/2006 23:02:24 NovellStandard NovellStandardMonthly gemini_1154145744 honeydew 000157 1 1 000142

10/29/2006 00:04:00 EsuOnbasePolicy EsuOnbaseFull esuonbase_1162098240 honeydew 000148 1 1

The date is always mm/dd/yyyy and the time is always hh:mm:ss. Some lines have more "fields".

I believe the fields are separated by one space, but I have not verified this (give me a minute and I'll check ...

Here's one of the above lines printed using cat -vet

07/28/2006 23:02:24 NovellStandard NovellStandardMonthly gemini_1154145744 honeydew 000157 1 1 000142$

Thanks,

sysglen

sysglen at 2007-7-7 3:48:36 > top of Java-index,Solaris Operating System,Solaris Essentials - General Technical Questions...
# 4
Yes, I did mean to "write over" the input file with the output file. The script (bash) is used to print a report and the file deleted.sysglen
sysglen at 2007-7-7 3:48:36 > top of Java-index,Solaris Operating System,Solaris Essentials - General Technical Questions...
# 5

Whenever I try to use the same filename for input and output with the sort command, the result is always the same--I end up with an empty file. Your example gave the very same result, however, I was able to rewrite the sort to work the way you want.

"unsorted-data-with-dates.txt" 4 lines, 373 characters

bash-2.05$ sort +6 -7 +0 -1 +1 -2 +4 -5 +8 -9 unsorted-data-with-dates.txt

10/29/2006 00:04:00 EsuOnbasePolicy EsuOnbaseFull esuonbase_1162098240 honeydew 000148 1 1

07/28/2006 23:02:24 NovellStandard NovellStandardMonthly gemini_1154145744 honeydew 000157 1 1 000142

07/29/2006 00:02:22 ELearningPolicy ELearningMonthly elearning_1154149342 honeydew 000157 1 1

11/13/2006 02:02:12 RobinPolicy RobinIncr robin_1163404932 honeydew 000167 2 1 000124

bash-2.05$ NBU_preview_out=unsorted-data-with-dates.txt

bash-2.05$ sort -o $NBU_preview_out +6 -7 +0 -1 +1 -2 +4 -5 +8 -9 unsorted-data-with-dates.txt $NBU_preview_out

Bus Error (core dumped)

bash-2.05$ cat unsorted-data-with-dates.txt

bash-2.05$

Instead of using the -k option, I used the old UNIX style of using sort. +6 means skip over the first 6 fields. -7 makes it sort on the 7th field. +0 and -1 makes the 1st field the 2nd key, and so on. Basically, the number I use for the -n is the key field in each position.

John

sun_powered at 2007-7-7 3:48:36 > top of Java-index,Solaris Operating System,Solaris Essentials - General Technical Questions...
# 6

John,

Thanks for looking into the sort. I have narrowed down the conditions where it fails. Look at the follow script and it's output:

cat sort.test.sh

#!/bin/bash

NBU_preview_out="sort.test.input"

cat $NBU_preview_out

echo "sort ====================================================================="

sort -o $NBU_preview_out -k 7 -k 1.7,1.10 -k 1.1,1.5 -k 2 -k 5-k 9$NBU_preview_out

cat $NBU_preview_out

and now running the above script:

~/sort.test.sh

11/20/2006 22:03:50 EsuObwebPolicy EsuObwebIncr esuobweb_1164081830 honeydew 000154 2 1

11/21/2006 00:03:36 BannerProductionApp ProdAppIncremental kermit_1164089016 honeydew 000154 2 1

11/22/2006 05:46:04 ZeusPolicy ZeusIncr zeus_1164195964 honeydew 000154 2 0

sort =====================================================================

11/22/2006 05:46:04 ZeusPolicy ZeusIncr zeus_1164195964 honeydew 000154 2 0

11/20/2006 22:03:50 EsuObwebPolicy EsuObwebIncr esuobweb_1164081830 honeydew 000154 2 1

11/21/2006 00:03:36 BannerProductionApp ProdAppIncremental kermit_1164089016 honeydew 000154 2 1

Note: The record dated 11/22/2006 has been sorted to the top.It looks like the last sort key (-k 9) is sorting ahead of the third key (-k 1.1,1.5).

Thanks and have a good holiday,

sysglen

sysglen at 2007-7-7 3:48:36 > top of Java-index,Solaris Operating System,Solaris Essentials - General Technical Questions...