[Linux-users] Sort Question

C M Reinehr cmr
Fri Aug 3 06:55:49 PDT 2007


Tom,

On Thursday 02 August 2007 16:01, tom marinis wrote:
> I think is fairly simple problem but I simply can't get my head
> around it.  I guess my brain needs to go in for some warranty
> work :)
>
> Maybe someone here can point me to a newgroup for further tips
> or make a helpful suggestion?
>
> Here it is.
>
> I have a listing of number in a textfile, lets say something
> like this;
>
> less sourcefile.txt
>
> 3:51:12:74:41:43:13
> 8:33:36:37:39:41:9
> 1:6:23:24:27:39:34
>
> etc...
>
>
> My thinking is to use "sort", using the numeric option.
>
> Reading the man instructions, they say that I can use
> options -gn, but -g or -n  simply does the same thing.
> When I try to "sort" the textfile, I get something
> like this;
>
> $ sort -t: -g inputfile.txt > outputfile.txt
>
> 1:6:23:24:27:39:34
> 3:51:12:74:41:43:13
> 8:33:36:37:39:41:9
>
> Which is nice, but what the results I expected to
> generate are something different.  I need to sort by
> field as well, so what I want to see from output
> is something like this;
>
> 1:6:23:24:27:34:39
> 3:12:13:41:43:51:74
> 8:9:33:36:37:39:41
>
>
> Do I use something else other than sort, or have I missed
> something about sort that's very obvious?
>
> I'm trying to review the archives, but I don't have a
> clue where to find this topic mentioned anywhere.
>
> Thanks muchly...
>
> Tom.

Let me be sure I understand your question. It sounds as if you want to sort 
both the order of the rows AND the fields within the rows (both column order 
& row order). If that's the case, sort can not do that, as it will sort only 
the rows. I would think that you are going to have to use something like awk, 
or perl to get the job done. I'm not aware of any simple utility to sort 
fields within a row.

HTH

cmr

-- 
Debian 'Etch' - Registered Linux User #241964
--------
"More laws, less justice." -- Marcus Tullius Ciceroca, 42 BC



More information about the Linux-users mailing list