Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'sort' giving me heartburn

Status
Not open for further replies.

Coderifous

Programmer
Dec 13, 2001
782
US
Hey all,

I'm a perl guy, and not really a stranger to unix, not a guru either (about to be obvious).

I'm needing to sort some data, and I'm getting screwy results. I'll post a line or two of notional data, and then the sort command I'm using.

Notional Data: (substitut dashes for spaces; s/-/ /g;)
Code:
--3---W1234537831234--EA00001--BLAHBLAHBLAH----------------------------------223
--3---W1234537841234--EA00001--BLAHBLAHBLAH----------------------------------013
--3---W1234637891234--EA00001--BLAHBLAHBLAH----------------------------------123
--3---W1834537891234--EA00001--BLAHBLAHBLAH----------------------------------023
Remember: There are no dashes, I put them here to keep count of spaces.
Now imagine have a gig's worth of data (single file) in that shape that needs to be sorted.
The data is in a fixed width 80-column format.

Here is the sort command:
Code:
sort -y - n -k 2.2,2 -k 5.1,5 file.txt
What I am trying to do is sort on the first 13-digit number (absolute characters 8-20, inclusive) and then the last number, way off to the right (absolute characters 78-80, inclusive).

My sort command + arguments isn't doing what I want it to do. Can anyone spot the problem? It seems to be taking into consideration the Character before the 13-digit number. It doesn't really make sense.

Is there a way to sort, specifying keys by absolute position? Rather than worry about sort's interpretation of fields? Also, I wonder if there is a way to have sort show the user exactly what the keys are, as interpreted from the arguments. That might help the trouble shooting process.

Any help is greatly appreciated!

--jim
 
PS - there is really only 4 lines of data there, shorter lines should be joined with the larger lines preceding them.

--jim
 
OK - figured it out. N'ermind.

For the curious:

No one could have possibly helped me, becuase I didn't post enough notional data. Some of the records to not have a character in position 7. This throws off the idea of where the 'column' starts. I was assuming that the second character of the second column was always the first digit in the 13-digit number. This isn't the case when the 7-character is missing. That's what screwed up my sort. Solution:
use the -t arg and specify a separator that doesn't exist. That way the entire line is field one and I can specify fields by absolute position now.

Thanks to anyone that took the time,
--jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top