Multiplying digits inside numbers based on position of digit

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











up vote
0
down vote

favorite












I have list of numbers like this:



0987656787689
2345453326780
3453212332345
1324532449876
1234532444568
3245321343456
1324354532376
1234532153457


I would like to sort the numbers based on the results of multiplication of digits in positions sixth and seventh, so the results are like this:



3245321343456
3453212332345
1234532153457
1234532444568
1324532449876
2345453326780
1324354532376
0987656787689









share|improve this question



























    up vote
    0
    down vote

    favorite












    I have list of numbers like this:



    0987656787689
    2345453326780
    3453212332345
    1324532449876
    1234532444568
    3245321343456
    1324354532376
    1234532153457


    I would like to sort the numbers based on the results of multiplication of digits in positions sixth and seventh, so the results are like this:



    3245321343456
    3453212332345
    1234532153457
    1234532444568
    1324532449876
    2345453326780
    1324354532376
    0987656787689









    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have list of numbers like this:



      0987656787689
      2345453326780
      3453212332345
      1324532449876
      1234532444568
      3245321343456
      1324354532376
      1234532153457


      I would like to sort the numbers based on the results of multiplication of digits in positions sixth and seventh, so the results are like this:



      3245321343456
      3453212332345
      1234532153457
      1234532444568
      1324532449876
      2345453326780
      1324354532376
      0987656787689









      share|improve this question















      I have list of numbers like this:



      0987656787689
      2345453326780
      3453212332345
      1324532449876
      1234532444568
      3245321343456
      1324354532376
      1234532153457


      I would like to sort the numbers based on the results of multiplication of digits in positions sixth and seventh, so the results are like this:



      3245321343456
      3453212332345
      1234532153457
      1234532444568
      1324532449876
      2345453326780
      1324354532376
      0987656787689






      sort numeric-data






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 10 mins ago









      Jeff Schaller

      33.9k851113




      33.9k851113










      asked 37 mins ago









      Koran

      345




      345




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          Using awk:



          $ awk ' print substr($0,6,1)*substr($0,7,1) ' <file
          30
          15
          2
          6
          6
          2
          20
          6


          Sorting the original numbers based on the the above result (this was a followup question in a comment):



          $ awk ' print substr($0,6,1)*substr($0,7,1) ' <file | paste - file | sort -n | cut -f 2
          3245321343456
          3453212332345
          1234532153457
          1234532444568
          1324532449876
          2345453326780
          1324354532376
          0987656787689


          This pastes the result of the multiplication together with the original numbers as two separate tab-delimited columns, then sorts it numerically and extracts the second column (the original numbers).






          share|improve this answer






















          • thank you very much this is stunning I spent three days on this ;(
            – Koran
            22 mins ago






          • 1




            @Koran Yes, asking followup questions is generally frowned upon. The question should be complete from the start. If you keep adding to it or changing it, you will invalidate given answers, and people will just be confused when trying to follow what's going on.
            – Kusalananda
            16 mins ago







          • 1




            @Goro I did update the question. sorry about confusion thank you
            – Koran
            16 mins ago

















          up vote
          1
          down vote













          Perl to the rescue!



          perl -F// -lane 'print $F[5] * $F[6]' < file



          • -n reads the input line by line


          • -a splits each line into the @F array


          • -F tells how to split


          • // means to split everywhere, i.e. into single characters


          • -l removes newlines from input and adds them to output





          share|improve this answer




















          • thank you very much for the quick response! Appreciated! I have one last question please, how can I sort the numbers based on the multiplication of the digits in positions 6 and 7?
            – Koran
            31 mins ago










          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
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f475321%2fmultiplying-digits-inside-numbers-based-on-position-of-digit%23new-answer', 'question_page');

          );

          Post as a guest






























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          Using awk:



          $ awk ' print substr($0,6,1)*substr($0,7,1) ' <file
          30
          15
          2
          6
          6
          2
          20
          6


          Sorting the original numbers based on the the above result (this was a followup question in a comment):



          $ awk ' print substr($0,6,1)*substr($0,7,1) ' <file | paste - file | sort -n | cut -f 2
          3245321343456
          3453212332345
          1234532153457
          1234532444568
          1324532449876
          2345453326780
          1324354532376
          0987656787689


          This pastes the result of the multiplication together with the original numbers as two separate tab-delimited columns, then sorts it numerically and extracts the second column (the original numbers).






          share|improve this answer






















          • thank you very much this is stunning I spent three days on this ;(
            – Koran
            22 mins ago






          • 1




            @Koran Yes, asking followup questions is generally frowned upon. The question should be complete from the start. If you keep adding to it or changing it, you will invalidate given answers, and people will just be confused when trying to follow what's going on.
            – Kusalananda
            16 mins ago







          • 1




            @Goro I did update the question. sorry about confusion thank you
            – Koran
            16 mins ago














          up vote
          1
          down vote



          accepted










          Using awk:



          $ awk ' print substr($0,6,1)*substr($0,7,1) ' <file
          30
          15
          2
          6
          6
          2
          20
          6


          Sorting the original numbers based on the the above result (this was a followup question in a comment):



          $ awk ' print substr($0,6,1)*substr($0,7,1) ' <file | paste - file | sort -n | cut -f 2
          3245321343456
          3453212332345
          1234532153457
          1234532444568
          1324532449876
          2345453326780
          1324354532376
          0987656787689


          This pastes the result of the multiplication together with the original numbers as two separate tab-delimited columns, then sorts it numerically and extracts the second column (the original numbers).






          share|improve this answer






















          • thank you very much this is stunning I spent three days on this ;(
            – Koran
            22 mins ago






          • 1




            @Koran Yes, asking followup questions is generally frowned upon. The question should be complete from the start. If you keep adding to it or changing it, you will invalidate given answers, and people will just be confused when trying to follow what's going on.
            – Kusalananda
            16 mins ago







          • 1




            @Goro I did update the question. sorry about confusion thank you
            – Koran
            16 mins ago












          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          Using awk:



          $ awk ' print substr($0,6,1)*substr($0,7,1) ' <file
          30
          15
          2
          6
          6
          2
          20
          6


          Sorting the original numbers based on the the above result (this was a followup question in a comment):



          $ awk ' print substr($0,6,1)*substr($0,7,1) ' <file | paste - file | sort -n | cut -f 2
          3245321343456
          3453212332345
          1234532153457
          1234532444568
          1324532449876
          2345453326780
          1324354532376
          0987656787689


          This pastes the result of the multiplication together with the original numbers as two separate tab-delimited columns, then sorts it numerically and extracts the second column (the original numbers).






          share|improve this answer














          Using awk:



          $ awk ' print substr($0,6,1)*substr($0,7,1) ' <file
          30
          15
          2
          6
          6
          2
          20
          6


          Sorting the original numbers based on the the above result (this was a followup question in a comment):



          $ awk ' print substr($0,6,1)*substr($0,7,1) ' <file | paste - file | sort -n | cut -f 2
          3245321343456
          3453212332345
          1234532153457
          1234532444568
          1324532449876
          2345453326780
          1324354532376
          0987656787689


          This pastes the result of the multiplication together with the original numbers as two separate tab-delimited columns, then sorts it numerically and extracts the second column (the original numbers).







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 22 mins ago

























          answered 26 mins ago









          Kusalananda

          109k14213336




          109k14213336











          • thank you very much this is stunning I spent three days on this ;(
            – Koran
            22 mins ago






          • 1




            @Koran Yes, asking followup questions is generally frowned upon. The question should be complete from the start. If you keep adding to it or changing it, you will invalidate given answers, and people will just be confused when trying to follow what's going on.
            – Kusalananda
            16 mins ago







          • 1




            @Goro I did update the question. sorry about confusion thank you
            – Koran
            16 mins ago
















          • thank you very much this is stunning I spent three days on this ;(
            – Koran
            22 mins ago






          • 1




            @Koran Yes, asking followup questions is generally frowned upon. The question should be complete from the start. If you keep adding to it or changing it, you will invalidate given answers, and people will just be confused when trying to follow what's going on.
            – Kusalananda
            16 mins ago







          • 1




            @Goro I did update the question. sorry about confusion thank you
            – Koran
            16 mins ago















          thank you very much this is stunning I spent three days on this ;(
          – Koran
          22 mins ago




          thank you very much this is stunning I spent three days on this ;(
          – Koran
          22 mins ago




          1




          1




          @Koran Yes, asking followup questions is generally frowned upon. The question should be complete from the start. If you keep adding to it or changing it, you will invalidate given answers, and people will just be confused when trying to follow what's going on.
          – Kusalananda
          16 mins ago





          @Koran Yes, asking followup questions is generally frowned upon. The question should be complete from the start. If you keep adding to it or changing it, you will invalidate given answers, and people will just be confused when trying to follow what's going on.
          – Kusalananda
          16 mins ago





          1




          1




          @Goro I did update the question. sorry about confusion thank you
          – Koran
          16 mins ago




          @Goro I did update the question. sorry about confusion thank you
          – Koran
          16 mins ago












          up vote
          1
          down vote













          Perl to the rescue!



          perl -F// -lane 'print $F[5] * $F[6]' < file



          • -n reads the input line by line


          • -a splits each line into the @F array


          • -F tells how to split


          • // means to split everywhere, i.e. into single characters


          • -l removes newlines from input and adds them to output





          share|improve this answer




















          • thank you very much for the quick response! Appreciated! I have one last question please, how can I sort the numbers based on the multiplication of the digits in positions 6 and 7?
            – Koran
            31 mins ago














          up vote
          1
          down vote













          Perl to the rescue!



          perl -F// -lane 'print $F[5] * $F[6]' < file



          • -n reads the input line by line


          • -a splits each line into the @F array


          • -F tells how to split


          • // means to split everywhere, i.e. into single characters


          • -l removes newlines from input and adds them to output





          share|improve this answer




















          • thank you very much for the quick response! Appreciated! I have one last question please, how can I sort the numbers based on the multiplication of the digits in positions 6 and 7?
            – Koran
            31 mins ago












          up vote
          1
          down vote










          up vote
          1
          down vote









          Perl to the rescue!



          perl -F// -lane 'print $F[5] * $F[6]' < file



          • -n reads the input line by line


          • -a splits each line into the @F array


          • -F tells how to split


          • // means to split everywhere, i.e. into single characters


          • -l removes newlines from input and adds them to output





          share|improve this answer












          Perl to the rescue!



          perl -F// -lane 'print $F[5] * $F[6]' < file



          • -n reads the input line by line


          • -a splits each line into the @F array


          • -F tells how to split


          • // means to split everywhere, i.e. into single characters


          • -l removes newlines from input and adds them to output






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 33 mins ago









          choroba

          25.1k34269




          25.1k34269











          • thank you very much for the quick response! Appreciated! I have one last question please, how can I sort the numbers based on the multiplication of the digits in positions 6 and 7?
            – Koran
            31 mins ago
















          • thank you very much for the quick response! Appreciated! I have one last question please, how can I sort the numbers based on the multiplication of the digits in positions 6 and 7?
            – Koran
            31 mins ago















          thank you very much for the quick response! Appreciated! I have one last question please, how can I sort the numbers based on the multiplication of the digits in positions 6 and 7?
          – Koran
          31 mins ago




          thank you very much for the quick response! Appreciated! I have one last question please, how can I sort the numbers based on the multiplication of the digits in positions 6 and 7?
          – Koran
          31 mins ago

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f475321%2fmultiplying-digits-inside-numbers-based-on-position-of-digit%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Displaying single band from multi-band raster using QGIS

          How many registers does an x86_64 CPU actually have?