 |
|
 |
|
01-30-06 02:32 AM
Hi,
Here is some data:
aaa,-1.09221e+06,-30955,35.569
bbb,1.13284e+06,67479,16.735
ccc,1.78407e+06,93986,20.9255
ddd,25.92,4,6.48
eee,108.65,25,4.32
I want to sort them by the second column. "sort -t, -n -k 2,2" does not
work. Maybe sort does not understand "e+06". Can any one help? I am
using /bin/sh on a solaris 8 server.
Thanks!
[ Post a follow-up to this message ]
|
|
|
 |
|
|
01-30-06 02:32 AM
whcui@yahoo.com wrote:
> Hi,
>
>
> Here is some data:
> aaa,-1.09221e+06,-30955,35.569
> bbb,1.13284e+06,67479,16.735
> ccc,1.78407e+06,93986,20.9255
> ddd,25.92,4,6.48
> eee,108.65,25,4.32
>
>
> I want to sort them by the second column. "sort -t, -n -k 2,2" does not
> work. Maybe sort does not understand "e+06". Can any one help? I am
> using /bin/sh on a solaris 8 server.
>
>
> Thanks!
>
Yes, the -n option doesn't recognise e+06. GNU sort has a -g option that
does.
Robert
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
01-30-06 02:32 AM
On 27 Jan 2006 07:02:21 -0800, whcui@yahoo.com
<whcui@yahoo.com> wrote:
> Hi,
>
>
> Here is some data:
> aaa,-1.09221e+06,-30955,35.569
> bbb,1.13284e+06,67479,16.735
> ccc,1.78407e+06,93986,20.9255
> ddd,25.92,4,6.48
> eee,108.65,25,4.32
>
>
> I want to sort them by the second column. "sort -t, -n -k 2,2" does not
> work. Maybe sort does not understand "e+06". Can any one help? I am
> using /bin/sh on a solaris 8 server.
>
Try -g instead of -n. I'm not sure if that is a GNU enhancement of the
sort command. If your sort does not support -g:
while IFS=, read c1 c2 rest_of_line; do
printf "%s,%d,%s\n" "$c1" "$c2" "$rest_of_line"
done | sort -t, -n -k 2,2
--
Life's the same, except for the shoes.
- The Cars
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
01-30-06 02:32 AM
whcui@yahoo.com wrote:
> Hi,
>
>
> Here is some data:
> aaa,-1.09221e+06,-30955,35.569
> bbb,1.13284e+06,67479,16.735
> ccc,1.78407e+06,93986,20.9255
> ddd,25.92,4,6.48
> eee,108.65,25,4.32
>
>
> I want to sort them by the second column. "sort -t, -n -k 2,2" does not
> work. Maybe sort does not understand "e+06".
ruby -e 'puts ARGF.sort_by{|x|x.split(",")[1].to_f}' myfile
[ Post a follow-up to this message ]
|
|
|
 |
|
|
|
|
Sponsored Links |
 |
 |
|
|
 |
All times are GMT. The time now is 03:21 PM. |
 |
|
|
 |
|
 |
|
|
 |
|
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
|
|
|
|
Medical and Health forum | Computer Games Reviews | Graphics design forum
|
 |
|
 |
|