Loading ...
Sorry, an error occurred while loading the content.

sorting based on numercial value

Expand Messages
  • googler
    I have a text file with a number of lines in it. Each line has the same format, say something like below. I want to sort
    Message 1 of 4 , May 2 3:24 PM
    • 0 Attachment
      I have a text file with a number of lines in it. Each line has the
      same format, say something like below.

      <string1> <string2> <number> <string3>

      I want to sort this file based on the numerical value of the <number>
      field. How can I do this in vim? Thanks.

      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • John Beckett
      ... The n gives a numeric sort, based on the first number in each line. It is also possible to include a pattern. There are two options. First, skip
      Message 2 of 4 , May 2 3:49 PM
      • 0 Attachment
        googler wrote:
        > I have a text file with a number of lines in it. Each line
        > has the same format, say something like below.
        >
        > <string1> <string2> <number> <string3>
        >
        > I want to sort this file based on the numerical value of the
        > <number> field. How can I do this in vim? Thanks.

        If there are no numbers in string1 and string2:
        :sort n

        The 'n' gives a numeric sort, based on the first number in each
        line. It is also possible to include a pattern. There are two
        options. First, skip everything up to and including the pattern
        (sort on what comes next; that's the default). Second (if r flag
        specified), sort on the text matching the pattern.

        If a problem, give real examples of typical data.

        John

        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
      • Reid Thompson
        ... if the internal sort won t meet the requirements, use an external one and read the results back into the buffer -- You received this message from the
        Message 3 of 4 , May 2 3:53 PM
        • 0 Attachment
          On 5/2/2011 6:49 PM, John Beckett wrote:
          > googler wrote:
          >> I have a text file with a number of lines in it. Each line
          >> has the same format, say something like below.
          >>
          >> <string1> <string2> <number> <string3>
          >>
          >> I want to sort this file based on the numerical value of the
          >> <number> field. How can I do this in vim? Thanks.
          > If there are no numbers in string1 and string2:
          > :sort n
          >
          > The 'n' gives a numeric sort, based on the first number in each
          > line. It is also possible to include a pattern. There are two
          > options. First, skip everything up to and including the pattern
          > (sort on what comes next; that's the default). Second (if r flag
          > specified), sort on the text matching the pattern.
          >
          > If a problem, give real examples of typical data.
          >
          > John
          >
          if the internal sort won't meet the requirements, use an external one
          and read the results back into the buffer

          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php
        • Reid Thompson
          ... using v or ctrl-v to select all text... and then applying the external sort with appropriate params(wouldn t need the full path to sort depending on how
          Message 4 of 4 , May 2 4:12 PM
          • 0 Attachment
            On 5/2/2011 6:53 PM, Reid Thompson wrote:
            > On 5/2/2011 6:49 PM, John Beckett wrote:
            >> googler wrote:
            >>> I have a text file with a number of lines in it. Each line
            >>> has the same format, say something like below.
            >>>
            >>> <string1> <string2> <number> <string3>
            >>>
            >>> I want to sort this file based on the numerical value of the
            >>> <number> field. How can I do this in vim? Thanks.
            >> If there are no numbers in string1 and string2:
            >> :sort n
            >>
            >> The 'n' gives a numeric sort, based on the first number in each
            >> line. It is also possible to include a pattern. There are two
            >> options. First, skip everything up to and including the pattern
            >> (sort on what comes next; that's the default). Second (if r flag
            >> specified), sort on the text matching the pattern.
            >>
            >> If a problem, give real examples of typical data.
            >>
            >> John
            >>
            > if the internal sort won't meet the requirements, use an external one
            > and read the results back into the buffer
            >
            using v or ctrl-v to select all text...
            and then applying the external sort with appropriate params(wouldn't
            need the full path to sort depending on how your system is setup)


            aaaa bbbb cccc 1 adsff
            bbbb aaaa cccc 4 adsff
            dddd aaaa cccc 5 adsff
            dddd cccc aaaa 2 adsff
            dddd gggg aaaa 3 adsff
            ~
            ~
            ~
            ~
            ~
            ~
            ~
            ~
            ~
            ~
            ~
            ~
            ~
            ~
            ~
            ~
            ~
            ~
            ~
            :'<,'>! C:\unixutils\sort.exe -n -k4

            yields

            aaaa bbbb cccc 1 adsff
            dddd cccc aaaa 2 adsff
            dddd gggg aaaa 3 adsff
            bbbb aaaa cccc 4 adsff
            dddd aaaa cccc 5 adsff
            ~
            ~
            ~
            ~
            ~
            ~
            ~
            ~
            ~
            ~
            ~
            ~
            ~
            ~
            ~
            ~
            ~
            ~
            ~
            5 lines filtered

            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php
          Your message has been successfully submitted and would be delivered to recipients shortly.