Hi,
I want a list of entries in 3 space delimited columns. I want to sort entries based on the very first column. Rows can't be changed. For example:
If I have...
Abc Abc Acc
Bca Bda Bdd
Cab Cab Cbc
Dbc Dca Dda
Abc Abc Acc
the output should be...
Abc Abc Acc
Abc Abc Acc
Bca Bda Bdd
Cab Cab Cbc
Dbc Dca Dda
Any pointer on how to go about this will be appreciated.
Thanks
I got the ouptut mentioned in the orginal post by just using the sort command. Is that what your trying?
Thanks
Nagarajan Ganesan
The example given was not a good one I think. Basically, some columns can be empty and every row should also be arranged alphabatically.
Try...
Abc Acc
Bca Bda Bdd
Cbc
Dbc Dca Dda
Abc Abc Acc
to get....
Abc Acc
Abc Abc Acc
Bca Bda Bdd
Cbc
Dbc Dca Dda
reborg
4
$ echo 'Abc Acc
> Bca Bda Bdd
> Cbc
> Dbc Dca Dda
> Abc Abc Acc
> ' | sort
Abc Abc Acc
Abc Acc
Bca Bda Bdd
Cbc
Dbc Dca Dda
I tried with...
(blank space) Abc Acc
Bca Bda Bdd
(blank space) (blank space) Cbc
Dbc Dca Dda
Abc Abc Acc
I don't get...
Abc Abc Acc
(blank space) Abc Acc
Bca Bda Bdd
(blank space) (blank space) Cbc
Dbc Dca Dda
using sort command. It seems to be sorting using Column 1.
The following are the different inputs and output which i got using the sort command,
Input:1
cat /tmp/s1
Abc Acc
Bca Bda Bdd
Cbc
Dbc Dca Dda
Abc Abc Acc
sort -k1d /tmp/s1
OUTPUT
Abc Abc Acc
Abc Acc
Bca Bda Bdd
Cbc
Dbc Dca Dda
sort -k1d /tmp/s1 | sed -e 's/^ *//g'
OUTPUT
Abc Abc Acc
Abc Acc
Bca Bda Bdd
Cbc
Dbc Dca Dda
Input 2
Note:Blank space is different
cat /tmp/s2
Abc Acc
Bca Bda Bdd
Cbc
Dbc Dca Dda
Abc Abc Acc
sort -k1d /tmp/s2 | sed -e 's/^ *//g'
OUTPUT
Abc Abc Acc
Abc Acc
Bca Bda Bdd
Cbc
Dbc Dca Dda
Hope this helps.
Thanks
Nagarajan Ganesan.
Thanks anbu23. That's what I needed.