1752778 Members
5749 Online
108789 Solutions
New Discussion юеВ

Re: Sort problem

 
SOLVED
Go to solution
maberg
Occasional Advisor

Re: Sort problem

Maybe everyone is right, that we have been misusing this utility. Is there another way to sort a file using multi-column fields withing a record for sorting??
Dennis Handly
Acclaimed Contributor

Re: Sort problem

>Is there another way to sort a file using multi-column fields withing a record for sorting?

It's called COBOL. :-)
Except the numbers must be right justified in their fields. Of course the input procedure could fix them.
OldSchool
Honored Contributor

Re: Sort problem

Dennis' suggestion of:

sort -t# -k1.10n,1.19n file.text > test.sorted

should work, while:

sort -t# -k1.10n,1.19n -o test.sorted file.txt

*might* work...

what happens when you run either of those exactly as shown?
maberg
Occasional Advisor

Re: Sort problem

Result for ( sort -t# -k1.10n,1.19n ground.txt2 > test.sorted ):

1124688 Barrera
1998945 Warble
2327703 Rebholz
8 5032 Rebholz


Result for ( sort -t# -k1.10n,1.19n -o test.sorted ground.txt2 ):

1124688 Barrera
1998945 Warble
2327703 Rebholz
8 5032 Rebholz
James R. Ferguson
Acclaimed Contributor

Re: Sort problem

Hi (again):

> Dennis: It's called COBOL. :-)
Except the numbers must be right justified in their fields. Of course the input procedure could fix them.

And its what COBOL would call an input procedure that I used when I manufactured the temporary fixed-position sort key. The output procedure stripped it.

The use of '-o output' file doesn't matter in HP-UX. In AIX, this simple form WORKS (even without the '-t#'):

# sort -k1.10n,1.19n file

Regards!

...JRF...

Dennis Handly
Acclaimed Contributor

Re: Sort problem

>JRF: In AIX, this simple form WORKS (even without the '-t#'):

Ah, right. The first field obviously starts in column 1.

This appears to be a bug. It is stripping leading blanks BEFORE it looks at column 10. This is why that "8" is making it work.

maberg: Please contact the Response Center and file a bug report.