|
|
|
Need help on sort cmd in unix AIX
|
Original Message
|
Name: jds
Date: September 30, 2004 at 14:48:10 Pacific
Subject: Need help on sort cmd in unix AIXOS: windowsXPCPU/Ram: petium III/ram 256 |
Comment: Hi, Can some one help me with unix sort command? I have a file like this: 01 asd 8211 abcd 02 das 8211 fsdf 03 fes 8301 fsdf 04 sda 8213 cdsc 05 lkm 8321 acsd I want sort by first 2 char of third comlumn and then 4th conlumn the result would be like: 01 asd 8211 abcd 04 sda 8213 cdsc 02 das 8211 fsdf 05 lkm 8321 acsd 03 fes 8301 fsdf Thanks In advance
Report Offensive Message For Removal
|
|
Response Number 2
|
Name: jds
Date: September 30, 2004 at 23:32:23 Pacific
Subject: Need help on sort cmd in unix AIX |
Reply: (edit)Thank Nails. Could you explain how is it work? 3.2 means third conlumn first 2 char? 3.3 ???? 4 means 4th conlumn but what about ",4"? by 4 char? One more question: If I got second conlumn blank how can I ignore it? 01 asd 8211 abcd 02 8211 fsdf 03 fes 8301 fsdf 04 sda 8213 cdsc 05 lkm 8321 acsd It has fixed spaces. I still want sort it like this: 01 asd 8211 abcd 04 sda 8213 cdsc 02 8211 fsdf 05 lkm 8321 acsd 03 fes 8301 fsdf Thanks again
Report Offensive Follow Up For Removal
|
|
Response Number 3
|
Name: nails
Date: October 1, 2004 at 09:40:08 Pacific
Subject: Need help on sort cmd in unix AIX |
Reply: (edit)HI: Let's discuss your "blank" field question first: Just looking at the data, how do you know it's the second field blank? My eye says that it might be the 4th field? If it were me, I'd run a script (like an awk script?) against the data file and then do something if there's only 3 fields. One of the options of the sort command is the key field. Within the key field you have to give it a start and an end. If you use the dot operator, that's the start and stop postions with the key field: -k 3.2,3.3 In the above statement, start at the third field's 2nd character and end at the 3rd character. The second key is to start by the 4th field and end by the 4th field: -k 4,4 Since you're sorting by only 1 field, you probably can get by with: -k 4 but I always give it an end. Do a 'man sort' for more information. Regards, Nails
I include
Report Offensive Follow Up For Removal
|
|
Response Number 4
|
Name: jds
Date: October 1, 2004 at 14:37:25 Pacific
Subject: Need help on sort cmd in unix AIX |
Reply: (edit)Thank you so much for your help. For the second question I was typing in 2nd blank filed but when I submmit it just ignore the space in between. So i looks like 4th balnk. Sorry about that. BTW, the sort command give me the result like this: 01 asd 8211 abcd 02 das 8211 fsdf 04 sda 8213 cdsc 03 fes 8301 fsdf 05 lkm 8321 acsd seems -k3.1,3.2 not working for me properly. It doesn't stop at third's 2nd char.I'd like get result like this: 01 asd 8211 abcd 04 sda 8213 cdsc --ignore last 2 char"13" 02 das 8211 fsdf 05 lkm 8321 acsd --ignore last 2 char"21" 03 fes 8301 fsdf I was using this command: sort -k3.1,3.2 -k4,4 file Did i do something wrong? Thanks, James
Report Offensive Follow Up For Removal
|
|
Response Number 5
|
Name: nails
Date: October 1, 2004 at 16:39:53 Pacific
Subject: Need help on sort cmd in unix AIX |
Reply: (edit)James: Take a closer look at it. Per your original question, shouldn't it be: sort -k 3.2,3.3 -k 4 data.file It should be the second and third characters where you are using the first and second -k 3.1,3.2 Regards, Nails
Report Offensive Follow Up For Removal
|
|
Response Number 6
|
Name: jds
Date: October 2, 2004 at 22:55:48 Pacific
Subject: Need help on sort cmd in unix AIX |
Reply: (edit)Sorry for the confusing. If I want sort by "first 2 character of 3rd conlumn" It should be sort -k3.1,3.2 -k4,4 right? In this case I only need consider 82, 83 and ignore the rest chars of 3rd column. Thanks, James
Report Offensive Follow Up For Removal
|
Use following form to reply to current message:
|
|

|