sed 's/-([0-9.]+)/(1)/g' inputfile what does this command mean?

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











up vote
2
down vote

favorite












I am trying to find out what the following command means:



sed 's/-([0-9.]+)/(1)/g' inputfile


I know it has to do with non-digit characters.










share|improve this question









New contributor




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























    up vote
    2
    down vote

    favorite












    I am trying to find out what the following command means:



    sed 's/-([0-9.]+)/(1)/g' inputfile


    I know it has to do with non-digit characters.










    share|improve this question









    New contributor




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





















      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I am trying to find out what the following command means:



      sed 's/-([0-9.]+)/(1)/g' inputfile


      I know it has to do with non-digit characters.










      share|improve this question









      New contributor




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











      I am trying to find out what the following command means:



      sed 's/-([0-9.]+)/(1)/g' inputfile


      I know it has to do with non-digit characters.







      sed






      share|improve this question









      New contributor




      Quincy Darko 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




      Quincy Darko 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 18 mins ago









      ilkkachu

      51.5k678142




      51.5k678142






      New contributor




      Quincy Darko 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









      Quincy Darko

      211




      211




      New contributor




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





      New contributor





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






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




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote













          In GNU sed, it looks for a dash followed by some digits or dots, and replaces that with the same digits in parenthesis. That is, it turns -123.45 into (123.45).



          In standard sed, it looks for a dash, a digit or dot, and a plus sign, and then removes the dash and surrounds the rest in parenthesis. That is, it turns -1+ into (1+), but leaves stuff like -123 as-is.




          Taken apart, in the left-hand pattern, the dash matches itself, [0-9.] matches any one digit or dot, and the ( ) capture the part in between. In the replacement, the parenthesis are literal, and 1 puts back whatever was within the ( ).



          In extended regular expressions, a + means "one or more of the previous", so [0-9.]+ would mean "one or more digits or dots". In a standard regex, neither + or + has any special meaning, however, but GNU systems are a bit lax on that, and + takes the "one or more" sense there.



          Portably, that should be either



          sed -E 's/-([0-9.]+)/(1)/' 


          or



          sed 's/-([0-9.]1,)/(1)/' 


          Both of which will replace a dash in front of a number with parenthesis around it.






          share|improve this answer





























            up vote
            1
            down vote













            Looks like it changing the format of negative numbers from having a - in front of them to instead being surrounded by parentheses.



            It searches for a sequence that starts with - followed by a sequence of numerals and decimals [0-9.] being a match to numerals and decimals, and + modifying it to match one or more such character in a sequence. The sequence of numerals and decimals are inside (...), which is the first expression, and in the replacement clause, (1) will paste the first expression between (). End result is removal of a negative sign in front of a number and wrapping it in parentheses.



            So with an input of:



            test value: -123.4


            the output should be of the form



            test value: (123.4)





            share|improve this answer


















            • 2




              ...and adds parentheses around the result, too. Just changing the display style.
              – drewbenn
              13 mins ago






            • 1




              Ah, yes, I did miss that. I'll edit it in.
              – Christian Gibbons
              12 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
            );



            );






            Quincy Darko 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%2f471397%2fsed-s-0-9-1-g-inputfile-what-does-this-command-mean%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
            2
            down vote













            In GNU sed, it looks for a dash followed by some digits or dots, and replaces that with the same digits in parenthesis. That is, it turns -123.45 into (123.45).



            In standard sed, it looks for a dash, a digit or dot, and a plus sign, and then removes the dash and surrounds the rest in parenthesis. That is, it turns -1+ into (1+), but leaves stuff like -123 as-is.




            Taken apart, in the left-hand pattern, the dash matches itself, [0-9.] matches any one digit or dot, and the ( ) capture the part in between. In the replacement, the parenthesis are literal, and 1 puts back whatever was within the ( ).



            In extended regular expressions, a + means "one or more of the previous", so [0-9.]+ would mean "one or more digits or dots". In a standard regex, neither + or + has any special meaning, however, but GNU systems are a bit lax on that, and + takes the "one or more" sense there.



            Portably, that should be either



            sed -E 's/-([0-9.]+)/(1)/' 


            or



            sed 's/-([0-9.]1,)/(1)/' 


            Both of which will replace a dash in front of a number with parenthesis around it.






            share|improve this answer


























              up vote
              2
              down vote













              In GNU sed, it looks for a dash followed by some digits or dots, and replaces that with the same digits in parenthesis. That is, it turns -123.45 into (123.45).



              In standard sed, it looks for a dash, a digit or dot, and a plus sign, and then removes the dash and surrounds the rest in parenthesis. That is, it turns -1+ into (1+), but leaves stuff like -123 as-is.




              Taken apart, in the left-hand pattern, the dash matches itself, [0-9.] matches any one digit or dot, and the ( ) capture the part in between. In the replacement, the parenthesis are literal, and 1 puts back whatever was within the ( ).



              In extended regular expressions, a + means "one or more of the previous", so [0-9.]+ would mean "one or more digits or dots". In a standard regex, neither + or + has any special meaning, however, but GNU systems are a bit lax on that, and + takes the "one or more" sense there.



              Portably, that should be either



              sed -E 's/-([0-9.]+)/(1)/' 


              or



              sed 's/-([0-9.]1,)/(1)/' 


              Both of which will replace a dash in front of a number with parenthesis around it.






              share|improve this answer
























                up vote
                2
                down vote










                up vote
                2
                down vote









                In GNU sed, it looks for a dash followed by some digits or dots, and replaces that with the same digits in parenthesis. That is, it turns -123.45 into (123.45).



                In standard sed, it looks for a dash, a digit or dot, and a plus sign, and then removes the dash and surrounds the rest in parenthesis. That is, it turns -1+ into (1+), but leaves stuff like -123 as-is.




                Taken apart, in the left-hand pattern, the dash matches itself, [0-9.] matches any one digit or dot, and the ( ) capture the part in between. In the replacement, the parenthesis are literal, and 1 puts back whatever was within the ( ).



                In extended regular expressions, a + means "one or more of the previous", so [0-9.]+ would mean "one or more digits or dots". In a standard regex, neither + or + has any special meaning, however, but GNU systems are a bit lax on that, and + takes the "one or more" sense there.



                Portably, that should be either



                sed -E 's/-([0-9.]+)/(1)/' 


                or



                sed 's/-([0-9.]1,)/(1)/' 


                Both of which will replace a dash in front of a number with parenthesis around it.






                share|improve this answer














                In GNU sed, it looks for a dash followed by some digits or dots, and replaces that with the same digits in parenthesis. That is, it turns -123.45 into (123.45).



                In standard sed, it looks for a dash, a digit or dot, and a plus sign, and then removes the dash and surrounds the rest in parenthesis. That is, it turns -1+ into (1+), but leaves stuff like -123 as-is.




                Taken apart, in the left-hand pattern, the dash matches itself, [0-9.] matches any one digit or dot, and the ( ) capture the part in between. In the replacement, the parenthesis are literal, and 1 puts back whatever was within the ( ).



                In extended regular expressions, a + means "one or more of the previous", so [0-9.]+ would mean "one or more digits or dots". In a standard regex, neither + or + has any special meaning, however, but GNU systems are a bit lax on that, and + takes the "one or more" sense there.



                Portably, that should be either



                sed -E 's/-([0-9.]+)/(1)/' 


                or



                sed 's/-([0-9.]1,)/(1)/' 


                Both of which will replace a dash in front of a number with parenthesis around it.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 4 mins ago

























                answered 10 mins ago









                ilkkachu

                51.5k678142




                51.5k678142






















                    up vote
                    1
                    down vote













                    Looks like it changing the format of negative numbers from having a - in front of them to instead being surrounded by parentheses.



                    It searches for a sequence that starts with - followed by a sequence of numerals and decimals [0-9.] being a match to numerals and decimals, and + modifying it to match one or more such character in a sequence. The sequence of numerals and decimals are inside (...), which is the first expression, and in the replacement clause, (1) will paste the first expression between (). End result is removal of a negative sign in front of a number and wrapping it in parentheses.



                    So with an input of:



                    test value: -123.4


                    the output should be of the form



                    test value: (123.4)





                    share|improve this answer


















                    • 2




                      ...and adds parentheses around the result, too. Just changing the display style.
                      – drewbenn
                      13 mins ago






                    • 1




                      Ah, yes, I did miss that. I'll edit it in.
                      – Christian Gibbons
                      12 mins ago














                    up vote
                    1
                    down vote













                    Looks like it changing the format of negative numbers from having a - in front of them to instead being surrounded by parentheses.



                    It searches for a sequence that starts with - followed by a sequence of numerals and decimals [0-9.] being a match to numerals and decimals, and + modifying it to match one or more such character in a sequence. The sequence of numerals and decimals are inside (...), which is the first expression, and in the replacement clause, (1) will paste the first expression between (). End result is removal of a negative sign in front of a number and wrapping it in parentheses.



                    So with an input of:



                    test value: -123.4


                    the output should be of the form



                    test value: (123.4)





                    share|improve this answer


















                    • 2




                      ...and adds parentheses around the result, too. Just changing the display style.
                      – drewbenn
                      13 mins ago






                    • 1




                      Ah, yes, I did miss that. I'll edit it in.
                      – Christian Gibbons
                      12 mins ago












                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote









                    Looks like it changing the format of negative numbers from having a - in front of them to instead being surrounded by parentheses.



                    It searches for a sequence that starts with - followed by a sequence of numerals and decimals [0-9.] being a match to numerals and decimals, and + modifying it to match one or more such character in a sequence. The sequence of numerals and decimals are inside (...), which is the first expression, and in the replacement clause, (1) will paste the first expression between (). End result is removal of a negative sign in front of a number and wrapping it in parentheses.



                    So with an input of:



                    test value: -123.4


                    the output should be of the form



                    test value: (123.4)





                    share|improve this answer














                    Looks like it changing the format of negative numbers from having a - in front of them to instead being surrounded by parentheses.



                    It searches for a sequence that starts with - followed by a sequence of numerals and decimals [0-9.] being a match to numerals and decimals, and + modifying it to match one or more such character in a sequence. The sequence of numerals and decimals are inside (...), which is the first expression, and in the replacement clause, (1) will paste the first expression between (). End result is removal of a negative sign in front of a number and wrapping it in parentheses.



                    So with an input of:



                    test value: -123.4


                    the output should be of the form



                    test value: (123.4)






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited 9 mins ago

























                    answered 22 mins ago









                    Christian Gibbons

                    261110




                    261110







                    • 2




                      ...and adds parentheses around the result, too. Just changing the display style.
                      – drewbenn
                      13 mins ago






                    • 1




                      Ah, yes, I did miss that. I'll edit it in.
                      – Christian Gibbons
                      12 mins ago












                    • 2




                      ...and adds parentheses around the result, too. Just changing the display style.
                      – drewbenn
                      13 mins ago






                    • 1




                      Ah, yes, I did miss that. I'll edit it in.
                      – Christian Gibbons
                      12 mins ago







                    2




                    2




                    ...and adds parentheses around the result, too. Just changing the display style.
                    – drewbenn
                    13 mins ago




                    ...and adds parentheses around the result, too. Just changing the display style.
                    – drewbenn
                    13 mins ago




                    1




                    1




                    Ah, yes, I did miss that. I'll edit it in.
                    – Christian Gibbons
                    12 mins ago




                    Ah, yes, I did miss that. I'll edit it in.
                    – Christian Gibbons
                    12 mins ago










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









                     

                    draft saved


                    draft discarded


















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












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











                    Quincy Darko 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%2f471397%2fsed-s-0-9-1-g-inputfile-what-does-this-command-mean%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    What does second last employer means? [closed]

                    Installing NextGIS Connect into QGIS 3?

                    One-line joke