Results 1 to 2 of 2

Thread: [SOLVED] Bash Sorting by Numbers

  1. #1
    Join Date
    Mar 2008
    Location
    Somerset, NJ
    Beans
    147
    Distro
    Ubuntu 11.04 Natty Narwhal

    [SOLVED] Bash Sorting by Numbers

    Hi everyone.

    I have a file containing a list of names with a numbers attached, in the following format:

    jsmith: 25
    tomf: 39
    melrom: 6

    And I want to offer the option of sorting the entire list based on the number on the right. For instance, say they want to do this (I'm using getopts for the args) and they type ./samplescript -n to sort by number, I'd like the output to be:

    melrom: 6
    jsmith: 25
    tomf: 39

    I'm just not sure how to implement this.

  2. #2
    Join Date
    Sep 2007
    Location
    Cambridge, MA
    Beans
    635

    Re: Bash Sorting by Numbers

    sort -n -k 2

Tags for this Thread

Bookmarks

Posting Permissions

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