How to sort? 
Author Message
 How to sort?

Hi,

  How to sort the data file like this.

   2  4    3.25025E-03
   3  2    3.33731E-03
   4  6    3.32962E-03
   5  9    3.21431E-03
   6  4    3.15137E-03
   7  1    3.19278E-03
   8  4    3.36131E-03
   9  2    3.48622E-03
   10  5   3.42362E-03
   11  4    3.22574E-03
   1  11    3.41709E-03
   2  15    3.68377E-03
   3  7     3.86876E-03
   4  14    3.89766E-03
   5  9     3.74598E-03
   6  14    3.57971E-03
   7  16    3.51235E-03
   8  14    3.02648E-03
   9  21    2.45176E-03
   10 12    2.22753E-03

   ..  .... . .........
   ..   ... . .........

   17  11    2.13257E-03
   1  6    3.36285E-03
   2  6    3.49023E-03

   such that it looks like this

    1  1   3.4234E-03
    1  2   3.7565E-03
    1  3   4.6656E-03
    .. ..  ..........

    5  1   4.6464E-03
    5  2   2.7576E-03
    .. .. ...........

    20 1   3.4058E-03
    20 2   3.0563E-03

    Please help me with your kind suggestions

   Raj
   Bangalore
   India.



Tue, 26 Apr 2005 14:20:22 GMT  
 How to sort?

Quote:

> Hi,

>   How to sort the data file like this.

>    2  4    3.25025E-03
>    3  2    3.33731E-03
>    4  6    3.32962E-03

    You don't need awk for this; use the sort command (with the -n
    option).

    "man sort" for more information.

--
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2002, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License



Tue, 26 Apr 2005 14:45:59 GMT  
 How to sort?

Quote:


> >Hi,

> >  How to sort the data file like this.

> >   2  4    3.25025E-03
> >   3  2    3.33731E-03
> >   4  6    3.32962E-03

>     You don't need awk for this; use the sort command (with the -n
>     option).

>     "man sort" for more information.

actually my linux sort has a -g option which is even better!
(-n doesn't work with x.xxEyy type figures - at least not on sun or sgi
anyway)

jen



Tue, 26 Apr 2005 22:48:39 GMT  
 How to sort?
Hi Raj,

You could use external unix or unix-like MsDos/NT 'sort' (e.g. GNU sort or
Mks Toolkit):

cat file_name | sort - k 1,1n -k 2,2n

or write (or copy) example of internal sort in Awk (read all file in arrays
and sort inside Awk program).

Regards,
-Joseph


Quote:
> Hi,

>   How to sort the data file like this.

>    2  4    3.25025E-03
>    3  2    3.33731E-03
>    4  6    3.32962E-03
>    5  9    3.21431E-03
>    6  4    3.15137E-03
>    7  1    3.19278E-03
>    8  4    3.36131E-03
>    9  2    3.48622E-03
>    10  5   3.42362E-03
>    11  4    3.22574E-03
>    1  11    3.41709E-03
>    2  15    3.68377E-03
>    3  7     3.86876E-03
>    4  14    3.89766E-03
>    5  9     3.74598E-03
>    6  14    3.57971E-03
>    7  16    3.51235E-03
>    8  14    3.02648E-03
>    9  21    2.45176E-03
>    10 12    2.22753E-03

>    ..  .... . .........
>    ..   ... . .........

>    17  11    2.13257E-03
>    1  6    3.36285E-03
>    2  6    3.49023E-03

>    such that it looks like this

>     1  1   3.4234E-03
>     1  2   3.7565E-03
>     1  3   4.6656E-03
>     .. ..  ..........

>     5  1   4.6464E-03
>     5  2   2.7576E-03
>     .. .. ...........

>     20 1   3.4058E-03
>     20 2   3.0563E-03

>     Please help me with your kind suggestions

>    Raj
>    Bangalore
>    India.




Tue, 26 Apr 2005 23:23:20 GMT  
 How to sort?

Quote:

> actually my linux sort has a -g option which is even better!
> (-n doesn't work with x.xxEyy type figures - at least not on sun or sgi
> anyway)

Hi Jen,
        this is not necessary in this case: the data were to be sorted
according to first two fields (integers).

Stepan



Fri, 29 Apr 2005 18:41:29 GMT  
 How to sort?

doh  *grin*  It's because I've recently been bitten by the
-n not sorting gawk numberic output (which likes E output for
large numbers)

the linux (gnu) sort -g feature was much appreciated in those cases
(after we had figured why some of the largest companies in australia
were down in the groups with the tiny ones :(

Good Call...
Jen

Quote:


> > actually my linux sort has a -g option which is even better!
> > (-n doesn't work with x.xxEyy type figures - at least not on sun or sgi
> > anyway)

> Hi Jen,
>         this is not necessary in this case: the data were to be sorted
> according to first two fields (integers).

> Stepan



Sat, 30 Apr 2005 15:09:26 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Sort (List sorts...)

2. UNIX sort exponents (bc|sort)

3. Binary Sort/Merge Sort in awk

4. ANN: New release of S.C.A. Micro Templates (Browse Header Sort and Reverse Sort Template)

5. Sort of Sorts

6. All Sorts of Sorts

7. All Sorts of Sorts

8. All Sorts of Sorts

9. All Sorts of Sorts

10. Straight Insertion Sort and Binary Insertion Sort

11. Bubble sort/Selection sort help neded.

12. Sorting a file w/o SORT verb

 

 
Powered by phpBB® Forum Software