|
Home > Archive > Unix Shell > September 2006 > Unix Sort Question
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Unix Sort Question
|
|
| amerar@iwc.net 2006-09-08, 7:34 pm |
| Hi All,
I'm trying to sort this random data by the number in the second field:
ART_VW,1,TRANS_ID,XEN,VARCHAR2,10
ART_VW,10,NAME_FIRST,XEN,VARCHAR2,15
ART_VW,11,NAME_MIDDLE,XEN,VARCHAR2,15
ART_VW,12,NAME_SUFFIX,XEN,VARCHAR2,6
ART_VW,13,CITZEN,XEN,VARCHAR2,2
ART_VW,14,SEX,XEN,VARCHAR2,1
ART_VW,15,POP_GROUP,XEN,VARCHAR2,1
ART_VW,16,ETH,XEN,VARCHAR2,1
ART_VW,17,DEPEND2,XEN,NUMBER,22
I was trying this: sort -u -t, -k2,2 n
But it does not work. I want it to be in numerical order..........
Any help is much appreciated.
Thanks!
| |
| bobmct 2006-09-08, 7:34 pm |
| amerar@iwc.net wrote:
> Hi All,
>
> I'm trying to sort this random data by the number in the second field:
>
> ART_VW,1,TRANS_ID,XEN,VARCHAR2,10
> ART_VW,10,NAME_FIRST,XEN,VARCHAR2,15
> ART_VW,11,NAME_MIDDLE,XEN,VARCHAR2,15
> ART_VW,12,NAME_SUFFIX,XEN,VARCHAR2,6
> ART_VW,13,CITZEN,XEN,VARCHAR2,2
> ART_VW,14,SEX,XEN,VARCHAR2,1
> ART_VW,15,POP_GROUP,XEN,VARCHAR2,1
> ART_VW,16,ETH,XEN,VARCHAR2,1
> ART_VW,17,DEPEND2,XEN,NUMBER,22
>
> I was trying this: sort -u -t, -k2,2 n
>
> But it does not work. I want it to be in numerical order..........
>
> Any help is much appreciated.
>
> Thanks!
Try this:
sort -t "," +1 filein >fileout
and let us know if that works?
| |
| balreddy.gattu@gmail.com 2006-09-11, 7:41 pm |
| sort -t "," -n +1 filein>fileout
will sort the based on the 2nd column in the file.
Thanks,
Bal reddy Gattu
bobmct wrote:
> amerar@iwc.net wrote:
>
>
> Try this:
>
> sort -t "," +1 filein >fileout
>
> and let us know if that works?
| |
| megadave@gmail.com 2006-09-12, 1:26 pm |
|
amerar@iwc.net wrote:
> Hi All,
>
> I'm trying to sort this random data by the number in the second field:
>
> ART_VW,1,TRANS_ID,XEN,VARCHAR2,10
> ART_VW,10,NAME_FIRST,XEN,VARCHAR2,15
> ART_VW,11,NAME_MIDDLE,XEN,VARCHAR2,15
> ART_VW,12,NAME_SUFFIX,XEN,VARCHAR2,6
> ART_VW,13,CITZEN,XEN,VARCHAR2,2
> ART_VW,14,SEX,XEN,VARCHAR2,1
> ART_VW,15,POP_GROUP,XEN,VARCHAR2,1
> ART_VW,16,ETH,XEN,VARCHAR2,1
> ART_VW,17,DEPEND2,XEN,NUMBER,22
>
> I was trying this: sort -u -t, -k2,2 n
>
> But it does not work. I want it to be in numerical order..........
Add a "-n" to the sort args to tell it to sort in numberic order. By
default it uses ascii/alphabetic order
>
> Any help is much appreciated.
>
> Thanks!
| |
| news.t-online.de 2006-09-23, 7:29 am |
| amerar@iwc.net wrote:
> Hi All,
>
> I'm trying to sort this random data by the number in the second field:
>
> ART_VW,1,TRANS_ID,XEN,VARCHAR2,10
> ART_VW,10,NAME_FIRST,XEN,VARCHAR2,15
> ART_VW,11,NAME_MIDDLE,XEN,VARCHAR2,15
> ART_VW,12,NAME_SUFFIX,XEN,VARCHAR2,6
> ART_VW,13,CITZEN,XEN,VARCHAR2,2
> ART_VW,14,SEX,XEN,VARCHAR2,1
> ART_VW,15,POP_GROUP,XEN,VARCHAR2,1
> ART_VW,16,ETH,XEN,VARCHAR2,1
> ART_VW,17,DEPEND2,XEN,NUMBER,22
>
> I was trying this: sort -u -t, -k2,2 n
>
> But it does not work. I want it to be in numerical order..........
>
> Any help is much appreciated.
>
> Thanks!
>
the -n option sorts nuerically
| |
| Spiros Bousbouras 2006-09-23, 1:27 pm |
| amerar@iwc.net wrote:
> Hi All,
>
> I'm trying to sort this random data by the number in the second field:
>
> ART_VW,1,TRANS_ID,XEN,VARCHAR2,10
> ART_VW,10,NAME_FIRST,XEN,VARCHAR2,15
> ART_VW,11,NAME_MIDDLE,XEN,VARCHAR2,15
> ART_VW,12,NAME_SUFFIX,XEN,VARCHAR2,6
> ART_VW,13,CITZEN,XEN,VARCHAR2,2
> ART_VW,14,SEX,XEN,VARCHAR2,1
> ART_VW,15,POP_GROUP,XEN,VARCHAR2,1
> ART_VW,16,ETH,XEN,VARCHAR2,1
> ART_VW,17,DEPEND2,XEN,NUMBER,22
>
> I was trying this: sort -u -t, -k2,2 n
>
> But it does not work. I want it to be in numerical order..........
Is this a joke ? The data is already sorted according to
the number in the second field. In any case
sort -u -t, -k2,2 n *will* work as long as there's no space
between n and 2 because otherwise sort thinks that n is
the name of a file.
|
|
|
|
|