Moving the last six digits to the beginning of numbers

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











up vote
1
down vote

favorite












I am using Twitter to pull news into an email, and the last six fields are the date and time. I would like these to be the first six fields. What's the command in awk to move the last n fields to the start of the line?



I have tried googling it but all the examples given assume each line has the same number of fields



example:



76356378090986
08976357627980089
089723571237809209
0897253712730912838798
908916523568909887
876756467890
09876535467890
765643324343
467890876543
234567890987654
123456789009876543
54323456789876
09876543345678
123456789009876
12345678998765


result:



09098676356378
98008908976357627
809209089723571237
8387980897253712730912
909887908916523568
467890876756
46789009876535
324343765643
876543467890
987654234567890
876543123456789009
78987654323456
34567809876543
009876123456789
99876512345678









share|improve this question









New contributor




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























    up vote
    1
    down vote

    favorite












    I am using Twitter to pull news into an email, and the last six fields are the date and time. I would like these to be the first six fields. What's the command in awk to move the last n fields to the start of the line?



    I have tried googling it but all the examples given assume each line has the same number of fields



    example:



    76356378090986
    08976357627980089
    089723571237809209
    0897253712730912838798
    908916523568909887
    876756467890
    09876535467890
    765643324343
    467890876543
    234567890987654
    123456789009876543
    54323456789876
    09876543345678
    123456789009876
    12345678998765


    result:



    09098676356378
    98008908976357627
    809209089723571237
    8387980897253712730912
    909887908916523568
    467890876756
    46789009876535
    324343765643
    876543467890
    987654234567890
    876543123456789009
    78987654323456
    34567809876543
    009876123456789
    99876512345678









    share|improve this question









    New contributor




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





















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I am using Twitter to pull news into an email, and the last six fields are the date and time. I would like these to be the first six fields. What's the command in awk to move the last n fields to the start of the line?



      I have tried googling it but all the examples given assume each line has the same number of fields



      example:



      76356378090986
      08976357627980089
      089723571237809209
      0897253712730912838798
      908916523568909887
      876756467890
      09876535467890
      765643324343
      467890876543
      234567890987654
      123456789009876543
      54323456789876
      09876543345678
      123456789009876
      12345678998765


      result:



      09098676356378
      98008908976357627
      809209089723571237
      8387980897253712730912
      909887908916523568
      467890876756
      46789009876535
      324343765643
      876543467890
      987654234567890
      876543123456789009
      78987654323456
      34567809876543
      009876123456789
      99876512345678









      share|improve this question









      New contributor




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











      I am using Twitter to pull news into an email, and the last six fields are the date and time. I would like these to be the first six fields. What's the command in awk to move the last n fields to the start of the line?



      I have tried googling it but all the examples given assume each line has the same number of fields



      example:



      76356378090986
      08976357627980089
      089723571237809209
      0897253712730912838798
      908916523568909887
      876756467890
      09876535467890
      765643324343
      467890876543
      234567890987654
      123456789009876543
      54323456789876
      09876543345678
      123456789009876
      12345678998765


      result:



      09098676356378
      98008908976357627
      809209089723571237
      8387980897253712730912
      909887908916523568
      467890876756
      46789009876535
      324343765643
      876543467890
      987654234567890
      876543123456789009
      78987654323456
      34567809876543
      009876123456789
      99876512345678






      text-processing awk






      share|improve this question









      New contributor




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











      share|improve this question









      New contributor




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









      share|improve this question




      share|improve this question








      edited 13 mins ago









      Rui F Ribeiro

      37k1273117




      37k1273117






      New contributor




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









      asked 27 mins ago









      marco

      1204




      1204




      New contributor




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





      New contributor





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






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




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          3
          down vote













          With sed:



          sed 's/(.*)(.6)/21/'





          share|improve this answer




















          • sooooooo elegant ;-)
            – Goro
            18 mins ago

















          up vote
          1
          down vote













          cat file | sed -e 's/(.)/1 /g' | awk ' for (i = 1; i <= NF; i++) printf "%s" FS, $((NF-7+i) % NF+1); print ""' | sed 's/ //g'
          09098676356378
          98008908976357627
          809209089723571237
          8387980897253712730912
          909887908916523568
          467890876756
          46789009876535
          324343765643
          876543467890
          987654234567890
          876543123456789009
          78987654323456
          34567809876543
          009876123456789
          99876512345678





          share|improve this answer




















          • that's a clear example of [Humor] Useless use of cat. sed is able to read a file. Having used awk, why also call sed (twice)?
            – Isaac
            2 mins ago










          • @Isaac thank you for sharing. It is the idea, the first sed created spaces between digits and the last sed removed them , it is an idea and still valied regardless if whether it is reckless or not ;-)
            – Goro
            43 secs ago


















          up vote
          0
          down vote













          With sed:



          sed 's/(.*)(.6)/21/'


          Or:



          sed -E 's/(.*)(.6)/21/'



          With (GNU) awk:



          awk 'print gensub(/(.*)(.6)/,"21",1)'





          share




















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



            );






            marco 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%2f473964%2fmoving-the-last-six-digits-to-the-beginning-of-numbers%23new-answer', 'question_page');

            );

            Post as a guest






























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            3
            down vote













            With sed:



            sed 's/(.*)(.6)/21/'





            share|improve this answer




















            • sooooooo elegant ;-)
              – Goro
              18 mins ago














            up vote
            3
            down vote













            With sed:



            sed 's/(.*)(.6)/21/'





            share|improve this answer




















            • sooooooo elegant ;-)
              – Goro
              18 mins ago












            up vote
            3
            down vote










            up vote
            3
            down vote









            With sed:



            sed 's/(.*)(.6)/21/'





            share|improve this answer












            With sed:



            sed 's/(.*)(.6)/21/'






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 19 mins ago









            Stéphane Chazelas

            287k53531868




            287k53531868











            • sooooooo elegant ;-)
              – Goro
              18 mins ago
















            • sooooooo elegant ;-)
              – Goro
              18 mins ago















            sooooooo elegant ;-)
            – Goro
            18 mins ago




            sooooooo elegant ;-)
            – Goro
            18 mins ago












            up vote
            1
            down vote













            cat file | sed -e 's/(.)/1 /g' | awk ' for (i = 1; i <= NF; i++) printf "%s" FS, $((NF-7+i) % NF+1); print ""' | sed 's/ //g'
            09098676356378
            98008908976357627
            809209089723571237
            8387980897253712730912
            909887908916523568
            467890876756
            46789009876535
            324343765643
            876543467890
            987654234567890
            876543123456789009
            78987654323456
            34567809876543
            009876123456789
            99876512345678





            share|improve this answer




















            • that's a clear example of [Humor] Useless use of cat. sed is able to read a file. Having used awk, why also call sed (twice)?
              – Isaac
              2 mins ago










            • @Isaac thank you for sharing. It is the idea, the first sed created spaces between digits and the last sed removed them , it is an idea and still valied regardless if whether it is reckless or not ;-)
              – Goro
              43 secs ago















            up vote
            1
            down vote













            cat file | sed -e 's/(.)/1 /g' | awk ' for (i = 1; i <= NF; i++) printf "%s" FS, $((NF-7+i) % NF+1); print ""' | sed 's/ //g'
            09098676356378
            98008908976357627
            809209089723571237
            8387980897253712730912
            909887908916523568
            467890876756
            46789009876535
            324343765643
            876543467890
            987654234567890
            876543123456789009
            78987654323456
            34567809876543
            009876123456789
            99876512345678





            share|improve this answer




















            • that's a clear example of [Humor] Useless use of cat. sed is able to read a file. Having used awk, why also call sed (twice)?
              – Isaac
              2 mins ago










            • @Isaac thank you for sharing. It is the idea, the first sed created spaces between digits and the last sed removed them , it is an idea and still valied regardless if whether it is reckless or not ;-)
              – Goro
              43 secs ago













            up vote
            1
            down vote










            up vote
            1
            down vote









            cat file | sed -e 's/(.)/1 /g' | awk ' for (i = 1; i <= NF; i++) printf "%s" FS, $((NF-7+i) % NF+1); print ""' | sed 's/ //g'
            09098676356378
            98008908976357627
            809209089723571237
            8387980897253712730912
            909887908916523568
            467890876756
            46789009876535
            324343765643
            876543467890
            987654234567890
            876543123456789009
            78987654323456
            34567809876543
            009876123456789
            99876512345678





            share|improve this answer












            cat file | sed -e 's/(.)/1 /g' | awk ' for (i = 1; i <= NF; i++) printf "%s" FS, $((NF-7+i) % NF+1); print ""' | sed 's/ //g'
            09098676356378
            98008908976357627
            809209089723571237
            8387980897253712730912
            909887908916523568
            467890876756
            46789009876535
            324343765643
            876543467890
            987654234567890
            876543123456789009
            78987654323456
            34567809876543
            009876123456789
            99876512345678






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 19 mins ago









            Goro

            7,45253169




            7,45253169











            • that's a clear example of [Humor] Useless use of cat. sed is able to read a file. Having used awk, why also call sed (twice)?
              – Isaac
              2 mins ago










            • @Isaac thank you for sharing. It is the idea, the first sed created spaces between digits and the last sed removed them , it is an idea and still valied regardless if whether it is reckless or not ;-)
              – Goro
              43 secs ago

















            • that's a clear example of [Humor] Useless use of cat. sed is able to read a file. Having used awk, why also call sed (twice)?
              – Isaac
              2 mins ago










            • @Isaac thank you for sharing. It is the idea, the first sed created spaces between digits and the last sed removed them , it is an idea and still valied regardless if whether it is reckless or not ;-)
              – Goro
              43 secs ago
















            that's a clear example of [Humor] Useless use of cat. sed is able to read a file. Having used awk, why also call sed (twice)?
            – Isaac
            2 mins ago




            that's a clear example of [Humor] Useless use of cat. sed is able to read a file. Having used awk, why also call sed (twice)?
            – Isaac
            2 mins ago












            @Isaac thank you for sharing. It is the idea, the first sed created spaces between digits and the last sed removed them , it is an idea and still valied regardless if whether it is reckless or not ;-)
            – Goro
            43 secs ago





            @Isaac thank you for sharing. It is the idea, the first sed created spaces between digits and the last sed removed them , it is an idea and still valied regardless if whether it is reckless or not ;-)
            – Goro
            43 secs ago











            up vote
            0
            down vote













            With sed:



            sed 's/(.*)(.6)/21/'


            Or:



            sed -E 's/(.*)(.6)/21/'



            With (GNU) awk:



            awk 'print gensub(/(.*)(.6)/,"21",1)'





            share
























              up vote
              0
              down vote













              With sed:



              sed 's/(.*)(.6)/21/'


              Or:



              sed -E 's/(.*)(.6)/21/'



              With (GNU) awk:



              awk 'print gensub(/(.*)(.6)/,"21",1)'





              share






















                up vote
                0
                down vote










                up vote
                0
                down vote









                With sed:



                sed 's/(.*)(.6)/21/'


                Or:



                sed -E 's/(.*)(.6)/21/'



                With (GNU) awk:



                awk 'print gensub(/(.*)(.6)/,"21",1)'





                share












                With sed:



                sed 's/(.*)(.6)/21/'


                Or:



                sed -E 's/(.*)(.6)/21/'



                With (GNU) awk:



                awk 'print gensub(/(.*)(.6)/,"21",1)'






                share











                share


                share










                answered 6 mins ago









                Isaac

                7,73711137




                7,73711137




















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









                     

                    draft saved


                    draft discarded


















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












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











                    marco 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%2f473964%2fmoving-the-last-six-digits-to-the-beginning-of-numbers%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    What does second last employer means? [closed]

                    List of Gilmore Girls characters

                    Confectionery