1752726 Members
5868 Online
108789 Solutions
New Discussion юеВ

Re: Sort problem

 
SOLVED
Go to solution
Tingli
Esteemed Contributor

Re: Sort problem

Or:
sort -t'#' -k1.10n,1.19n file.txt -o test.sorted
maberg
Occasional Advisor

Re: Sort problem

I did try "sort -t# -k1.10nb,1.19nbb" and this was the result.

I am not trying to hide anything, but the total file length of the actual file is 1250 bytes in total length. It would be too large to effectively work with here since the small file still behaves the same way.

Result:
1124688 Barrera
1998945 Warble
2327703 Rebholz
8 5032 Rebholz
maberg
Occasional Advisor

Re: Sort problem

The sort utility is supposed to be able to sort fixed file formats. This works fine on a Solaris server. We are migrating away from the Solaris platform.

I tried "sort -t'#' -k1.10n,1.19n" and the result was:

Usage: sort [-AbcdfiMmnru] [-T Directory] [-tCharacter] [-y kilobytes] [-o File]
[-k Keydefinition].. [[+Position1][-Position2]].. [-z recsz] [File]..
1124688 Barrera
1998945 Warble
2327703 Rebholz
8 5032 Rebholz

James R. Ferguson
Acclaimed Contributor

Re: Sort problem

Hi (again):

> The "8" is another data component in column 1. It is just a data item. Other data characters can be accounted for in column 1 - 9, but not always.

Exactly. It (or any group of characters surrounded by whitespace, as the default field delimiter) constitutes a "field" in your file. This influences what 'sort()' sees as the n-th field you use as a sort key.

Re-read Mel's explanation of my original post and his second offering to you, too.

> Thanks for the input, but I am trying to use the sort utility only.

You _are_ the 'sort' to solve your problem. You simply need to invariantly define the _field_ you want to sort on. All I did was to manufacture a temporary sort-key; perform the requisite sort; and snip the manufacture key from the output.

Regards!

...JRF...
maberg
Occasional Advisor

Re: Sort problem

I appreciate everyone's input. It is very helpful to get ALL ideas. I am trying them all and I am trying to give you as much information as I know of about the file details.

I really appreciate the efforts here as I am at my wits end over this....
maberg
Occasional Advisor

Re: Sort problem

I am digesting Mel and James information and trying to adapt it. My understanding was the the -t option would cause sort to use the whole record as a fixed field when the -t specified a character not contained within the input record. The current job has been this way for a long time. I will try your suggestions again and do some tweaking.

Mel's output returned:
1998945 W,arble,
8 5032 Re,bholz,
1124688 B,arrera,
2327703 R,ebholz,
Tingli
Esteemed Contributor

Re: Sort problem

Give this a shot:

sort -t'#' -k1.10nb,1.19nb
James R. Ferguson
Acclaimed Contributor

Re: Sort problem

Hi (again):

> My understanding was the the -t option would cause sort to use the whole record as a fixed field when the -t specified a character not contained within the input record.

OK, I just figured out that that was why you kept specifying '-t#'. I guess I'm a bit dense today.

This doesn't work on HP-UX as logical as it would seem. It DOES WORK on AIX (and obviously Solaris) underscoring again that various UNIX dialects differ in the edge cases.

Regards!

...JRF...
OldSchool
Honored Contributor

Re: Sort problem

the man page for sort on HPUX lists the -t option.

you might try -t"#" or see if "stty -a" is using # for something...

Dennis Handly
Acclaimed Contributor

Re: Sort problem

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

This looks like the right command except that -o. You need to use ">" or move it sooner:
sort -t# -k1.10n,1.19n file.txt > test.sorted

>I tried "sort -t'#' -k1.10n,1.19n" and the result was: Usage: ...

Do you still get that "Usage:" message?