Find the answer to your Linux question:
Results 1 to 4 of 4
hi, I have a file with scientific notation numbers and I would like to short them. I found many sorting scripts in perl but I cant understand how they work. ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2012
    Posts
    53

    Sorting scientific notation numbers (perl)


    hi,

    I have a file with scientific notation numbers and I would like to short them. I found many sorting scripts in perl but I cant understand how they work. Basically, I want the highest number and the its number of line.
    Thank you.

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,356
    If your file contains only numbers, line by line, then this should do it:
    Code:
    sort -g your_file
    Edit: For reverse ordering there is also a switch.
    Check the man page
    Code:
    man sort
    Last edited by Irithori; 08-08-2013 at 11:47 AM.
    You must always face the curtain with a bow.

  3. #3
    Just Joined!
    Join Date
    Apr 2012
    Posts
    53
    Thank you but, I want also to get the number of the line. For example if the file is like
    0.12e-9
    0.4
    0.13e-2

    I want to get

    2 4

    Thank you

  4. #4
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,356
    Itīs the other way around, but basically:
    Code:
    cat -n your_file | sort -g -k2
    Reversing the columns (if you should need it) is left as an exercise
    You must always face the curtain with a bow.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •