Replacing strings in lines Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election Results Why I closed the “Why is Kali so hard” questionReordering strings in linuxDelete lines between 2 strings in SolarisReplacing a character at a random position using sed?Delete multiple lines in a fileHow to escape special characters in long sed stringFormatting text - insert newline before commented linesReplacing multiple lines in Unixreplacing and adding at the end of lines with one line sed commandExtract all line from a file that contains two strings in any positionAdding tags to a sentence on each line

I need to find the potential function of a vector field.

Do I really need recursive chmod to restrict access to a folder?

How much radiation do nuclear physics experiments expose researchers to nowadays?

What is the longest distance a 13th-level monk can jump while attacking on the same turn?

Does surprise arrest existing movement?

Can inflation occur in a positive-sum game currency system such as the Stack Exchange reputation system?

Is there a concise way to say "all of the X, one of each"?

Why did the IBM 650 use bi-quinary?

What does '1 unit of lemon juice' mean in a grandma's drink recipe?

Stars Make Stars

Determinant is linear as a function of each of the rows of the matrix.

How to recreate this effect in Photoshop?

If Jon Snow became King of the Seven Kingdoms what would his regnal number be?

Sorting numerically

How to deal with a team lead who never gives me credit?

How can players work together to take actions that are otherwise impossible?

If a contract sometimes uses the wrong name, is it still valid?

Why does Python start at index -1 when indexing a list from the end?

Does accepting a pardon have any bearing on trying that person for the same crime in a sovereign jurisdiction?

Withdrew £2800, but only £2000 shows as withdrawn on online banking; what are my obligations?

Why are there no cargo aircraft with "flying wing" design?

How can I fade player character when he goes inside or outside of the area?

Why is black pepper both grey and black?

Disable hyphenation for an entire paragraph



Replacing strings in lines



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questionReordering strings in linuxDelete lines between 2 strings in SolarisReplacing a character at a random position using sed?Delete multiple lines in a fileHow to escape special characters in long sed stringFormatting text - insert newline before commented linesReplacing multiple lines in Unixreplacing and adding at the end of lines with one line sed commandExtract all line from a file that contains two strings in any positionAdding tags to a sentence on each line



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I have lines like this:



 400 january ####
304 april ####
151 may ####
126 june ####
115 august ####
98 december ####


And I want them to look like this:



#### january 400 
#### april 304
#### may 151
#### june 126
#### august 115
#### december 98


I tried using this command, but no avail.



 sed -E 's/(.*)(.*)(.*) /3 2 1/'









share|improve this question






























    2















    I have lines like this:



     400 january ####
    304 april ####
    151 may ####
    126 june ####
    115 august ####
    98 december ####


    And I want them to look like this:



    #### january 400 
    #### april 304
    #### may 151
    #### june 126
    #### august 115
    #### december 98


    I tried using this command, but no avail.



     sed -E 's/(.*)(.*)(.*) /3 2 1/'









    share|improve this question


























      2












      2








      2








      I have lines like this:



       400 january ####
      304 april ####
      151 may ####
      126 june ####
      115 august ####
      98 december ####


      And I want them to look like this:



      #### january 400 
      #### april 304
      #### may 151
      #### june 126
      #### august 115
      #### december 98


      I tried using this command, but no avail.



       sed -E 's/(.*)(.*)(.*) /3 2 1/'









      share|improve this question
















      I have lines like this:



       400 january ####
      304 april ####
      151 may ####
      126 june ####
      115 august ####
      98 december ####


      And I want them to look like this:



      #### january 400 
      #### april 304
      #### may 151
      #### june 126
      #### august 115
      #### december 98


      I tried using this command, but no avail.



       sed -E 's/(.*)(.*)(.*) /3 2 1/'






      sed






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 12 at 15:02









      Rui F Ribeiro

      42.1k1483142




      42.1k1483142










      asked Apr 11 at 21:14









      Laura Laura

      433




      433




















          2 Answers
          2






          active

          oldest

          votes


















          2














          Try:



          $ sed -E 's/^(.*[0-9])(.*[[:alpha:]])(.*)/3 2 1/' file
          #### january 400
          #### april 304
          #### may 151
          #### june 126
          #### august 115
          #### december 98


          How it works



          • ^(.*[0-9]) matches from the beginning of the line to the last number of the line.


          • (.*[[:alpha:]]) matches from the after the above to the last alphabetic character on the line.


          • (.*) matches anything after the last alphabetic character on the line.


          Discussion



          Consider:



          sed -E 's/(.*)(.*)(.*) /3 2 1/'


          sed's regexes match leftmost-longest. That means that the first (.*) above matches the entire line. The remaining groups are empty. If we modify the command, this becomes clear:



          $ sed -E 's/(.*)(.*)(.*) /3=3 and 2=2 and 1=1/' file
          3= and 2= and 1= 400 january ####
          3= and 2= and 1= 304 april ####
          3= and 2= and 1= 151 may ####
          3= and 2= and 1= 126 june ####
          3= and 2= and 1= 115 august ####
          3= and 2= and 1= 98 december ####





          share|improve this answer
































            3














            Here is a simpler way to do it:



            awk 'print $3," "$2," "$1' file


            It just uses awk to print columns 3, 2, and 1 with two spaces between the 3rd and 2nd column and four spaces between the 2nd and 1st column.



            Output:



            #### january 400
            #### april 304
            #### may 151
            #### june 126
            #### august 115
            #### december 98


            If you want it to edit the file in place, use this command:



            awk -i inplace 'print $3," "$2," "$1' file





            share|improve this answer

























              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',
              autoActivateHeartbeat: false,
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              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%2f511999%2freplacing-strings-in-lines%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              2














              Try:



              $ sed -E 's/^(.*[0-9])(.*[[:alpha:]])(.*)/3 2 1/' file
              #### january 400
              #### april 304
              #### may 151
              #### june 126
              #### august 115
              #### december 98


              How it works



              • ^(.*[0-9]) matches from the beginning of the line to the last number of the line.


              • (.*[[:alpha:]]) matches from the after the above to the last alphabetic character on the line.


              • (.*) matches anything after the last alphabetic character on the line.


              Discussion



              Consider:



              sed -E 's/(.*)(.*)(.*) /3 2 1/'


              sed's regexes match leftmost-longest. That means that the first (.*) above matches the entire line. The remaining groups are empty. If we modify the command, this becomes clear:



              $ sed -E 's/(.*)(.*)(.*) /3=3 and 2=2 and 1=1/' file
              3= and 2= and 1= 400 january ####
              3= and 2= and 1= 304 april ####
              3= and 2= and 1= 151 may ####
              3= and 2= and 1= 126 june ####
              3= and 2= and 1= 115 august ####
              3= and 2= and 1= 98 december ####





              share|improve this answer





























                2














                Try:



                $ sed -E 's/^(.*[0-9])(.*[[:alpha:]])(.*)/3 2 1/' file
                #### january 400
                #### april 304
                #### may 151
                #### june 126
                #### august 115
                #### december 98


                How it works



                • ^(.*[0-9]) matches from the beginning of the line to the last number of the line.


                • (.*[[:alpha:]]) matches from the after the above to the last alphabetic character on the line.


                • (.*) matches anything after the last alphabetic character on the line.


                Discussion



                Consider:



                sed -E 's/(.*)(.*)(.*) /3 2 1/'


                sed's regexes match leftmost-longest. That means that the first (.*) above matches the entire line. The remaining groups are empty. If we modify the command, this becomes clear:



                $ sed -E 's/(.*)(.*)(.*) /3=3 and 2=2 and 1=1/' file
                3= and 2= and 1= 400 january ####
                3= and 2= and 1= 304 april ####
                3= and 2= and 1= 151 may ####
                3= and 2= and 1= 126 june ####
                3= and 2= and 1= 115 august ####
                3= and 2= and 1= 98 december ####





                share|improve this answer



























                  2












                  2








                  2







                  Try:



                  $ sed -E 's/^(.*[0-9])(.*[[:alpha:]])(.*)/3 2 1/' file
                  #### january 400
                  #### april 304
                  #### may 151
                  #### june 126
                  #### august 115
                  #### december 98


                  How it works



                  • ^(.*[0-9]) matches from the beginning of the line to the last number of the line.


                  • (.*[[:alpha:]]) matches from the after the above to the last alphabetic character on the line.


                  • (.*) matches anything after the last alphabetic character on the line.


                  Discussion



                  Consider:



                  sed -E 's/(.*)(.*)(.*) /3 2 1/'


                  sed's regexes match leftmost-longest. That means that the first (.*) above matches the entire line. The remaining groups are empty. If we modify the command, this becomes clear:



                  $ sed -E 's/(.*)(.*)(.*) /3=3 and 2=2 and 1=1/' file
                  3= and 2= and 1= 400 january ####
                  3= and 2= and 1= 304 april ####
                  3= and 2= and 1= 151 may ####
                  3= and 2= and 1= 126 june ####
                  3= and 2= and 1= 115 august ####
                  3= and 2= and 1= 98 december ####





                  share|improve this answer















                  Try:



                  $ sed -E 's/^(.*[0-9])(.*[[:alpha:]])(.*)/3 2 1/' file
                  #### january 400
                  #### april 304
                  #### may 151
                  #### june 126
                  #### august 115
                  #### december 98


                  How it works



                  • ^(.*[0-9]) matches from the beginning of the line to the last number of the line.


                  • (.*[[:alpha:]]) matches from the after the above to the last alphabetic character on the line.


                  • (.*) matches anything after the last alphabetic character on the line.


                  Discussion



                  Consider:



                  sed -E 's/(.*)(.*)(.*) /3 2 1/'


                  sed's regexes match leftmost-longest. That means that the first (.*) above matches the entire line. The remaining groups are empty. If we modify the command, this becomes clear:



                  $ sed -E 's/(.*)(.*)(.*) /3=3 and 2=2 and 1=1/' file
                  3= and 2= and 1= 400 january ####
                  3= and 2= and 1= 304 april ####
                  3= and 2= and 1= 151 may ####
                  3= and 2= and 1= 126 june ####
                  3= and 2= and 1= 115 august ####
                  3= and 2= and 1= 98 december ####






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Apr 11 at 21:27

























                  answered Apr 11 at 21:21









                  John1024John1024

                  48.7k5114129




                  48.7k5114129























                      3














                      Here is a simpler way to do it:



                      awk 'print $3," "$2," "$1' file


                      It just uses awk to print columns 3, 2, and 1 with two spaces between the 3rd and 2nd column and four spaces between the 2nd and 1st column.



                      Output:



                      #### january 400
                      #### april 304
                      #### may 151
                      #### june 126
                      #### august 115
                      #### december 98


                      If you want it to edit the file in place, use this command:



                      awk -i inplace 'print $3," "$2," "$1' file





                      share|improve this answer





























                        3














                        Here is a simpler way to do it:



                        awk 'print $3," "$2," "$1' file


                        It just uses awk to print columns 3, 2, and 1 with two spaces between the 3rd and 2nd column and four spaces between the 2nd and 1st column.



                        Output:



                        #### january 400
                        #### april 304
                        #### may 151
                        #### june 126
                        #### august 115
                        #### december 98


                        If you want it to edit the file in place, use this command:



                        awk -i inplace 'print $3," "$2," "$1' file





                        share|improve this answer



























                          3












                          3








                          3







                          Here is a simpler way to do it:



                          awk 'print $3," "$2," "$1' file


                          It just uses awk to print columns 3, 2, and 1 with two spaces between the 3rd and 2nd column and four spaces between the 2nd and 1st column.



                          Output:



                          #### january 400
                          #### april 304
                          #### may 151
                          #### june 126
                          #### august 115
                          #### december 98


                          If you want it to edit the file in place, use this command:



                          awk -i inplace 'print $3," "$2," "$1' file





                          share|improve this answer















                          Here is a simpler way to do it:



                          awk 'print $3," "$2," "$1' file


                          It just uses awk to print columns 3, 2, and 1 with two spaces between the 3rd and 2nd column and four spaces between the 2nd and 1st column.



                          Output:



                          #### january 400
                          #### april 304
                          #### may 151
                          #### june 126
                          #### august 115
                          #### december 98


                          If you want it to edit the file in place, use this command:



                          awk -i inplace 'print $3," "$2," "$1' file






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Apr 12 at 11:54

























                          answered Apr 11 at 21:42









                          Nasir RileyNasir Riley

                          3,0622410




                          3,0622410



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Unix & Linux Stack Exchange!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f511999%2freplacing-strings-in-lines%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

                              Cannot Extend partition with GParted The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsCan't increase partition size with GParted?GParted doesn't recognize the unallocated space after my current partitionWhat is the best way to add unallocated space located before to Ubuntu 12.04 partition with GParted live?I can't figure out how to extend my Arch home partition into free spaceGparted Linux Mint 18.1 issueTrying to extend but swap partition is showing as Unknown in Gparted, shows proper from fdiskRearrange partitions in gparted to extend a partitionUnable to extend partition even though unallocated space is next to it using GPartedAllocate free space to root partitiongparted: how to merge unallocated space with a partition

                              NetworkManager fails with “Could not find source connection”Trouble connecting to VPN using network-manager, while command line worksHow can I be notified about state changes to a VPN adapterBacktrack 5 R3 - Refuses to connect to VPNFeed all traffic through OpenVPN for a specific network namespace onlyRun daemon on startup in Debian once openvpn connection establishedpfsense tcp connection between openvpn and lan is brokenInternet connection problem with web browsers onlyWhy does NetworkManager explicitly support tun/tap devices?Browser issues with VPNTwo IP addresses assigned to the same network card - OpenVPN issues?Cannot connect to WiFi with nmcli, although secrets are provided