sort with -k greater than number of keys

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I'm trying to understand an existing script used in our project with the sort command



sort -t= -nr -k3 nos 


Where nos is a file with whitespace and numbers, for this example:
997 998 999 1000



The output is



999
998
997
1000


What I don't understand is why 1000 appears last. I suspect it is because of the argument -k3 when there is only key for each entry but I can't find anything in the documentation to say how it behaves when the specified key position doesn't exist.



Up until 4-digit numbers were included in the file this gave the expected result of sorting the numbers descending numerically.









share







New contributor




Chris R is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.























    up vote
    0
    down vote

    favorite












    I'm trying to understand an existing script used in our project with the sort command



    sort -t= -nr -k3 nos 


    Where nos is a file with whitespace and numbers, for this example:
    997 998 999 1000



    The output is



    999
    998
    997
    1000


    What I don't understand is why 1000 appears last. I suspect it is because of the argument -k3 when there is only key for each entry but I can't find anything in the documentation to say how it behaves when the specified key position doesn't exist.



    Up until 4-digit numbers were included in the file this gave the expected result of sorting the numbers descending numerically.









    share







    New contributor




    Chris R is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm trying to understand an existing script used in our project with the sort command



      sort -t= -nr -k3 nos 


      Where nos is a file with whitespace and numbers, for this example:
      997 998 999 1000



      The output is



      999
      998
      997
      1000


      What I don't understand is why 1000 appears last. I suspect it is because of the argument -k3 when there is only key for each entry but I can't find anything in the documentation to say how it behaves when the specified key position doesn't exist.



      Up until 4-digit numbers were included in the file this gave the expected result of sorting the numbers descending numerically.









      share







      New contributor




      Chris R is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I'm trying to understand an existing script used in our project with the sort command



      sort -t= -nr -k3 nos 


      Where nos is a file with whitespace and numbers, for this example:
      997 998 999 1000



      The output is



      999
      998
      997
      1000


      What I don't understand is why 1000 appears last. I suspect it is because of the argument -k3 when there is only key for each entry but I can't find anything in the documentation to say how it behaves when the specified key position doesn't exist.



      Up until 4-digit numbers were included in the file this gave the expected result of sorting the numbers descending numerically.







      sort





      share







      New contributor




      Chris R is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share







      New contributor




      Chris R is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share



      share






      New contributor




      Chris R is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 5 mins ago









      Chris R

      1011




      1011




      New contributor




      Chris R is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Chris R is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Chris R is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.

























          active

          oldest

          votes











          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          Chris R is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f476376%2fsort-with-k-greater-than-number-of-keys%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          Chris R is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          Chris R is a new contributor. Be nice, and check out our Code of Conduct.












          Chris R is a new contributor. Be nice, and check out our Code of Conduct.











          Chris R is a new contributor. Be nice, and check out our Code of Conduct.













           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f476376%2fsort-with-k-greater-than-number-of-keys%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          Peggy Mitchell

          Palaiologos

          The Forum (Inglewood, California)