|
Home > Archive > Unix Shell > February 2005 > Can unix sort handle multiple spaces as delimiter between fields? Can't get it to work
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 |
Can unix sort handle multiple spaces as delimiter between fields? Can't get it to work
|
|
| colin_lyse 2005-02-02, 5:56 pm |
| runing Sun Unix 5.8 on Sun-Fire-15000
i have a smal file (20k) that looks like the following. some fields have 1
space between them, others 2, others more. (. = space)
00290..S.....33.XS798............SUB.......SUB ACTIVE 19971202
00090..S.... 69KV..TSS30 TR LTC TR2 ACTIVE 20050201
00135..S.... 69KV..TSS30 TRLTC TR1 ACTIVE 20050201
the problem is that when i do the following
sort +2 -3 it works the 3rd the list is correctly sorted in the third column.
however, if I want to sort on the 4 colum and do
sort +4 -5 it does not work (see example above), it sorts by the 4th column
only in relation to the 3rd column (x goes first because of the 33), howve i
think it might be related to the 1 vs. 2 spaces.
I though about replacing the spaces with tabs, however some of the fields have
spaces within them leading to problems with alignment.
i also tried
sort -n -k 5,5 -k 4,4 -k 6,6 but that didn't work only if i stoped after
field 3
It seems like the problem is that after field 3 there are differing amounts of
space between fields .
any help greated appreciated.
| |
| Rakesh Sharma 2005-02-02, 5:56 pm |
|
colin_lyse wrote:
> runing Sun Unix 5.8 on Sun-Fire-15000
>
> i have a smal file (20k) that looks like the following. some fields
have 1
> space between them, others 2, others more. (. = space)
>
> 00290..S.....33.XS798............SUB.......SUB ACTIVE
19971202
> 00090..S.... 69KV..TSS30 TR LTC TR2 ACTIVE
20050201
> 00135..S.... 69KV..TSS30 TRLTC TR1 ACTIVE
20050201
>
> the problem is that when i do the following
>
> sort +2 -3 it works the 3rd the list is correctly sorted in the
third column.
> however, if I want to sort on the 4 colum and do
>
> sort +4 -5 it does not work (see example above), it sorts by the 4th
column
> only in relation to the 3rd column (x goes first because of the 33),
howve i
> think it might be related to the 1 vs. 2 spaces.
>
> I though about replacing the spaces with tabs, however some of the
fields have
> spaces within them leading to problems with alignment.
>
> i also tried
> sort -n -k 5,5 -k 4,4 -k 6,6 but that didn't work only if i stoped
after
> field 3
>
> It seems like the problem is that after field 3 there are differing
amounts of
> space between fields .
>
>
> any help greated appreciated.
sort -b ....
| |
| Greg Beeker 2005-02-03, 7:52 am |
|
Rakesh Sharma wrote:
> colin_lyse wrote:
fields[vbcol=seagreen]
> have 1
> 19971202
> 20050201
> 20050201
> third column.
4th[vbcol=seagreen]
> column
33),[vbcol=seagreen]
> howve i
[vbcol=seagreen]
> sort -b ....
After trying your example data, I noticed that the TRLTC (4th field)
had a space, so I changed the space to a ., and this seemed to work,
along with taking out the -3 or -5.
>sort +3 <data
00290 S 33.XS798 SUB SUB ACTIVE
19971202
00090 S 69KV..TSS30 TR.LTC TR2 ACTIVE
20050201
00135 S 69KV..TSS30 TRLTC TR1 ACTIVE
20050201
$ sort +4 <data
00290 S 33.XS798 SUB SUB ACTIVE
19971202
00135 S 69KV..TSS30 TRLTC TR1 ACTIVE
20050201
00090 S 69KV..TSS30 TR.LTC TR2 ACTIVE
20050201
In fact the -b was not needed, or didn't change the results.
| |
| Greg Beeker 2005-02-09, 8:51 pm |
|
Rakesh Sharma wrote:
> colin_lyse wrote:
fields[vbcol=seagreen]
> have 1
> 19971202
> 20050201
> 20050201
> third column.
4th[vbcol=seagreen]
> column
33),[vbcol=seagreen]
> howve i
[vbcol=seagreen]
> sort -b ....
After trying your example data, I noticed that the TRLTC (4th field)
had a space, so I changed the space to a ., and this seemed to work,
along with taking out the -3 or -5.
>sort +3 <data
00290 S 33.XS798 SUB SUB ACTIVE
19971202
00090 S 69KV..TSS30 TR.LTC TR2 ACTIVE
20050201
00135 S 69KV..TSS30 TRLTC TR1 ACTIVE
20050201
$ sort +4 <data
00290 S 33.XS798 SUB SUB ACTIVE
19971202
00135 S 69KV..TSS30 TRLTC TR1 ACTIVE
20050201
00090 S 69KV..TSS30 TR.LTC TR2 ACTIVE
20050201
In fact the -b was not needed, or didn't change the results.
|
|
|
|
|