1863013 Members
1556 Online
110446 Solutions
New Discussion

script wanted

 
SOLVED
Go to solution
peterchu
Super Advisor

script wanted

I have a very large file , the content as below,


11 11 "d1"
22 22 "a2"
33 33 "12"
44 44 "37"

I want to sort it by column 3 from small to large ( now the order should be 12 --> 37 --> a2 --> d1 ) so the result should be as below. besides , there are a "" sign on column 3 ,

33 33 "12"
44 44 "37"
22 22 "a2"
11 11 "d1"

What can I do ? thx
4 REPLIES 4
john korterman
Honored Contributor
Solution

Re: script wanted

Hi,

what is wrong with:
sort -k3

regards,
John K.
it would be nice if you always got a second chance
Simon Hargrave
Honored Contributor

Re: script wanted

The fact that there are quotes around the 3rd column is of no concequence, given it's there on every row, so will not differ as far as sort is concerned.

So you can simply sort on the 3rd field with: -

sort -k3 verylargefile
Bharat Katkar
Honored Contributor

Re: script wanted

Hi,
# cat abc
33 33 "12"
44 44 "37"
22 22 "a2"
11 11 "d1"
#
# sort -k3 abc
33 33 "12"
44 44 "37"
22 22 "a2"
11 11 "d1"
#

Works perfectly. And this is what you want.
Regards,
You need to know a lot to actually know how little you know
peterchu
Super Advisor

Re: script wanted

thx all