1 not defined in the RE?

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












3















My code goes like this:



cat file.ign | sed 's/^([^A-Za-z0-9]+ )/<ignore>1</ignore>/g'


Yet I receive an error saying :



sed: 1: "s/^([^A-Za-z0-9]+ )/<ig ...": 1 not defined in the RE









share|improve this question




























    3















    My code goes like this:



    cat file.ign | sed 's/^([^A-Za-z0-9]+ )/<ignore>1</ignore>/g'


    Yet I receive an error saying :



    sed: 1: "s/^([^A-Za-z0-9]+ )/<ig ...": 1 not defined in the RE









    share|improve this question


























      3












      3








      3








      My code goes like this:



      cat file.ign | sed 's/^([^A-Za-z0-9]+ )/<ignore>1</ignore>/g'


      Yet I receive an error saying :



      sed: 1: "s/^([^A-Za-z0-9]+ )/<ig ...": 1 not defined in the RE









      share|improve this question
















      My code goes like this:



      cat file.ign | sed 's/^([^A-Za-z0-9]+ )/<ignore>1</ignore>/g'


      Yet I receive an error saying :



      sed: 1: "s/^([^A-Za-z0-9]+ )/<ig ...": 1 not defined in the RE






      sed






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 7 at 7:23









      Rui F Ribeiro

      40.7k1479137




      40.7k1479137










      asked Feb 6 at 23:34









      Laura Laura

      313




      313




















          2 Answers
          2






          active

          oldest

          votes


















          6














          Parentheses are literal in basic regular expression (BRE) syntax - to make them denote a capture group, they must be escaped, as ( and )



          Additionally, as noted in a comment by @BenjaminW, + is also literal in BRE. GNU sed supports + as a quantifier in BRE:



          sed 's/^([^A-Za-z0-9]+ )/<ignore>1</ignore>/g'


          (but other implementations might not). Alternatively, turn on extended regular expression (ERE) mode using the -E or -r command line switch as appropriate (check your version's documentation):



          sed -E 's/^([^A-Za-z0-9]+ )/<ignore>1</ignore>/g'


          or use the POSIX-compliant quantifier 1,



          sed 's/^([^A-Za-z0-9]1, )/<ignore>1</ignore>/g'


          ASIDE the g (global replacement) modifier won't have any effect here, since ^ anchors the expression to the start of the pattern (which can occur only once per line)






          share|improve this answer




















          • 1





            Furthermore, + is only avalable in ERE; GNU sed supports it as an extension in BRE, but is has to be escaped.

            – Benjamin W.
            Feb 7 at 0:39











          • @BenjaminW. oops yes that's a good point - I missed that

            – steeldriver
            Feb 7 at 0:40











          • The -E also is GNU or FreeBSD sed, not in POSIX. If you're going to recommend a non-POSIX solution, mentioning that might help the reader.

            – Thomas Dickey
            Feb 7 at 1:20












          • sed 's#^[^A-Za-z0-9][^A-Za-z0-9]* #<ignore>&</ignore>#' will do the same in any sed, and it's hardly uglier than (..1,..)/..</../ ;-)

            – pizdelect
            Feb 7 at 5:47






          • 1





            @ThomasDickey But it looks like it has been accepted - not sure when it'll make it into the standard, though.

            – Benjamin W.
            Feb 7 at 14:10


















          0














          Using GNU sed, you can invoke as sed -E or else you can escape the parentheses in order to get the back-reference working, but if you're not using GNU sed, you can't rely on back references; POSIX sed doesn't (yet) support the -E or -r argument for Extended Regular Expressions (ERE) nor does it support GNU's Basic Regular Expression (BRE) backslash notation. (Here's more on POSIX ERE & BRE, though it doesn't speak in much depth about GNU's BRE implementation allowing escaping into ERE functionality.)



          Fortunately, (in this case) you don't need ERE. This should work for you:





          sed 's/^[^A-Za-z0-9][^A-Za-z0-9]* /<ignore>&</ignore>/' file.ign


          BRE doesn't support the + quantifier, so I needed to double the nonword character set so it would be "one or more" by requiring "one" and then "zero or more" of them. The ampersand (&) denotes the entire match. There's no need to have parentheses around everything in this case. (The beginning-of-line anchor ^ is zero-width and doesn't matter here.)



          I removed the cat because it's unnecessary. I also removed your /g modifier because the ^ anchor means this can only match once per line, so you'll never get a second match and therefore a global replacement doesn't do anything.






          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%2f499185%2f1-not-defined-in-the-re%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









            6














            Parentheses are literal in basic regular expression (BRE) syntax - to make them denote a capture group, they must be escaped, as ( and )



            Additionally, as noted in a comment by @BenjaminW, + is also literal in BRE. GNU sed supports + as a quantifier in BRE:



            sed 's/^([^A-Za-z0-9]+ )/<ignore>1</ignore>/g'


            (but other implementations might not). Alternatively, turn on extended regular expression (ERE) mode using the -E or -r command line switch as appropriate (check your version's documentation):



            sed -E 's/^([^A-Za-z0-9]+ )/<ignore>1</ignore>/g'


            or use the POSIX-compliant quantifier 1,



            sed 's/^([^A-Za-z0-9]1, )/<ignore>1</ignore>/g'


            ASIDE the g (global replacement) modifier won't have any effect here, since ^ anchors the expression to the start of the pattern (which can occur only once per line)






            share|improve this answer




















            • 1





              Furthermore, + is only avalable in ERE; GNU sed supports it as an extension in BRE, but is has to be escaped.

              – Benjamin W.
              Feb 7 at 0:39











            • @BenjaminW. oops yes that's a good point - I missed that

              – steeldriver
              Feb 7 at 0:40











            • The -E also is GNU or FreeBSD sed, not in POSIX. If you're going to recommend a non-POSIX solution, mentioning that might help the reader.

              – Thomas Dickey
              Feb 7 at 1:20












            • sed 's#^[^A-Za-z0-9][^A-Za-z0-9]* #<ignore>&</ignore>#' will do the same in any sed, and it's hardly uglier than (..1,..)/..</../ ;-)

              – pizdelect
              Feb 7 at 5:47






            • 1





              @ThomasDickey But it looks like it has been accepted - not sure when it'll make it into the standard, though.

              – Benjamin W.
              Feb 7 at 14:10















            6














            Parentheses are literal in basic regular expression (BRE) syntax - to make them denote a capture group, they must be escaped, as ( and )



            Additionally, as noted in a comment by @BenjaminW, + is also literal in BRE. GNU sed supports + as a quantifier in BRE:



            sed 's/^([^A-Za-z0-9]+ )/<ignore>1</ignore>/g'


            (but other implementations might not). Alternatively, turn on extended regular expression (ERE) mode using the -E or -r command line switch as appropriate (check your version's documentation):



            sed -E 's/^([^A-Za-z0-9]+ )/<ignore>1</ignore>/g'


            or use the POSIX-compliant quantifier 1,



            sed 's/^([^A-Za-z0-9]1, )/<ignore>1</ignore>/g'


            ASIDE the g (global replacement) modifier won't have any effect here, since ^ anchors the expression to the start of the pattern (which can occur only once per line)






            share|improve this answer




















            • 1





              Furthermore, + is only avalable in ERE; GNU sed supports it as an extension in BRE, but is has to be escaped.

              – Benjamin W.
              Feb 7 at 0:39











            • @BenjaminW. oops yes that's a good point - I missed that

              – steeldriver
              Feb 7 at 0:40











            • The -E also is GNU or FreeBSD sed, not in POSIX. If you're going to recommend a non-POSIX solution, mentioning that might help the reader.

              – Thomas Dickey
              Feb 7 at 1:20












            • sed 's#^[^A-Za-z0-9][^A-Za-z0-9]* #<ignore>&</ignore>#' will do the same in any sed, and it's hardly uglier than (..1,..)/..</../ ;-)

              – pizdelect
              Feb 7 at 5:47






            • 1





              @ThomasDickey But it looks like it has been accepted - not sure when it'll make it into the standard, though.

              – Benjamin W.
              Feb 7 at 14:10













            6












            6








            6







            Parentheses are literal in basic regular expression (BRE) syntax - to make them denote a capture group, they must be escaped, as ( and )



            Additionally, as noted in a comment by @BenjaminW, + is also literal in BRE. GNU sed supports + as a quantifier in BRE:



            sed 's/^([^A-Za-z0-9]+ )/<ignore>1</ignore>/g'


            (but other implementations might not). Alternatively, turn on extended regular expression (ERE) mode using the -E or -r command line switch as appropriate (check your version's documentation):



            sed -E 's/^([^A-Za-z0-9]+ )/<ignore>1</ignore>/g'


            or use the POSIX-compliant quantifier 1,



            sed 's/^([^A-Za-z0-9]1, )/<ignore>1</ignore>/g'


            ASIDE the g (global replacement) modifier won't have any effect here, since ^ anchors the expression to the start of the pattern (which can occur only once per line)






            share|improve this answer















            Parentheses are literal in basic regular expression (BRE) syntax - to make them denote a capture group, they must be escaped, as ( and )



            Additionally, as noted in a comment by @BenjaminW, + is also literal in BRE. GNU sed supports + as a quantifier in BRE:



            sed 's/^([^A-Za-z0-9]+ )/<ignore>1</ignore>/g'


            (but other implementations might not). Alternatively, turn on extended regular expression (ERE) mode using the -E or -r command line switch as appropriate (check your version's documentation):



            sed -E 's/^([^A-Za-z0-9]+ )/<ignore>1</ignore>/g'


            or use the POSIX-compliant quantifier 1,



            sed 's/^([^A-Za-z0-9]1, )/<ignore>1</ignore>/g'


            ASIDE the g (global replacement) modifier won't have any effect here, since ^ anchors the expression to the start of the pattern (which can occur only once per line)







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Feb 7 at 1:56

























            answered Feb 6 at 23:45









            steeldriversteeldriver

            36.4k35286




            36.4k35286







            • 1





              Furthermore, + is only avalable in ERE; GNU sed supports it as an extension in BRE, but is has to be escaped.

              – Benjamin W.
              Feb 7 at 0:39











            • @BenjaminW. oops yes that's a good point - I missed that

              – steeldriver
              Feb 7 at 0:40











            • The -E also is GNU or FreeBSD sed, not in POSIX. If you're going to recommend a non-POSIX solution, mentioning that might help the reader.

              – Thomas Dickey
              Feb 7 at 1:20












            • sed 's#^[^A-Za-z0-9][^A-Za-z0-9]* #<ignore>&</ignore>#' will do the same in any sed, and it's hardly uglier than (..1,..)/..</../ ;-)

              – pizdelect
              Feb 7 at 5:47






            • 1





              @ThomasDickey But it looks like it has been accepted - not sure when it'll make it into the standard, though.

              – Benjamin W.
              Feb 7 at 14:10












            • 1





              Furthermore, + is only avalable in ERE; GNU sed supports it as an extension in BRE, but is has to be escaped.

              – Benjamin W.
              Feb 7 at 0:39











            • @BenjaminW. oops yes that's a good point - I missed that

              – steeldriver
              Feb 7 at 0:40











            • The -E also is GNU or FreeBSD sed, not in POSIX. If you're going to recommend a non-POSIX solution, mentioning that might help the reader.

              – Thomas Dickey
              Feb 7 at 1:20












            • sed 's#^[^A-Za-z0-9][^A-Za-z0-9]* #<ignore>&</ignore>#' will do the same in any sed, and it's hardly uglier than (..1,..)/..</../ ;-)

              – pizdelect
              Feb 7 at 5:47






            • 1





              @ThomasDickey But it looks like it has been accepted - not sure when it'll make it into the standard, though.

              – Benjamin W.
              Feb 7 at 14:10







            1




            1





            Furthermore, + is only avalable in ERE; GNU sed supports it as an extension in BRE, but is has to be escaped.

            – Benjamin W.
            Feb 7 at 0:39





            Furthermore, + is only avalable in ERE; GNU sed supports it as an extension in BRE, but is has to be escaped.

            – Benjamin W.
            Feb 7 at 0:39













            @BenjaminW. oops yes that's a good point - I missed that

            – steeldriver
            Feb 7 at 0:40





            @BenjaminW. oops yes that's a good point - I missed that

            – steeldriver
            Feb 7 at 0:40













            The -E also is GNU or FreeBSD sed, not in POSIX. If you're going to recommend a non-POSIX solution, mentioning that might help the reader.

            – Thomas Dickey
            Feb 7 at 1:20






            The -E also is GNU or FreeBSD sed, not in POSIX. If you're going to recommend a non-POSIX solution, mentioning that might help the reader.

            – Thomas Dickey
            Feb 7 at 1:20














            sed 's#^[^A-Za-z0-9][^A-Za-z0-9]* #<ignore>&</ignore>#' will do the same in any sed, and it's hardly uglier than (..1,..)/..</../ ;-)

            – pizdelect
            Feb 7 at 5:47





            sed 's#^[^A-Za-z0-9][^A-Za-z0-9]* #<ignore>&</ignore>#' will do the same in any sed, and it's hardly uglier than (..1,..)/..</../ ;-)

            – pizdelect
            Feb 7 at 5:47




            1




            1





            @ThomasDickey But it looks like it has been accepted - not sure when it'll make it into the standard, though.

            – Benjamin W.
            Feb 7 at 14:10





            @ThomasDickey But it looks like it has been accepted - not sure when it'll make it into the standard, though.

            – Benjamin W.
            Feb 7 at 14:10













            0














            Using GNU sed, you can invoke as sed -E or else you can escape the parentheses in order to get the back-reference working, but if you're not using GNU sed, you can't rely on back references; POSIX sed doesn't (yet) support the -E or -r argument for Extended Regular Expressions (ERE) nor does it support GNU's Basic Regular Expression (BRE) backslash notation. (Here's more on POSIX ERE & BRE, though it doesn't speak in much depth about GNU's BRE implementation allowing escaping into ERE functionality.)



            Fortunately, (in this case) you don't need ERE. This should work for you:





            sed 's/^[^A-Za-z0-9][^A-Za-z0-9]* /<ignore>&</ignore>/' file.ign


            BRE doesn't support the + quantifier, so I needed to double the nonword character set so it would be "one or more" by requiring "one" and then "zero or more" of them. The ampersand (&) denotes the entire match. There's no need to have parentheses around everything in this case. (The beginning-of-line anchor ^ is zero-width and doesn't matter here.)



            I removed the cat because it's unnecessary. I also removed your /g modifier because the ^ anchor means this can only match once per line, so you'll never get a second match and therefore a global replacement doesn't do anything.






            share|improve this answer





























              0














              Using GNU sed, you can invoke as sed -E or else you can escape the parentheses in order to get the back-reference working, but if you're not using GNU sed, you can't rely on back references; POSIX sed doesn't (yet) support the -E or -r argument for Extended Regular Expressions (ERE) nor does it support GNU's Basic Regular Expression (BRE) backslash notation. (Here's more on POSIX ERE & BRE, though it doesn't speak in much depth about GNU's BRE implementation allowing escaping into ERE functionality.)



              Fortunately, (in this case) you don't need ERE. This should work for you:





              sed 's/^[^A-Za-z0-9][^A-Za-z0-9]* /<ignore>&</ignore>/' file.ign


              BRE doesn't support the + quantifier, so I needed to double the nonword character set so it would be "one or more" by requiring "one" and then "zero or more" of them. The ampersand (&) denotes the entire match. There's no need to have parentheses around everything in this case. (The beginning-of-line anchor ^ is zero-width and doesn't matter here.)



              I removed the cat because it's unnecessary. I also removed your /g modifier because the ^ anchor means this can only match once per line, so you'll never get a second match and therefore a global replacement doesn't do anything.






              share|improve this answer



























                0












                0








                0







                Using GNU sed, you can invoke as sed -E or else you can escape the parentheses in order to get the back-reference working, but if you're not using GNU sed, you can't rely on back references; POSIX sed doesn't (yet) support the -E or -r argument for Extended Regular Expressions (ERE) nor does it support GNU's Basic Regular Expression (BRE) backslash notation. (Here's more on POSIX ERE & BRE, though it doesn't speak in much depth about GNU's BRE implementation allowing escaping into ERE functionality.)



                Fortunately, (in this case) you don't need ERE. This should work for you:





                sed 's/^[^A-Za-z0-9][^A-Za-z0-9]* /<ignore>&</ignore>/' file.ign


                BRE doesn't support the + quantifier, so I needed to double the nonword character set so it would be "one or more" by requiring "one" and then "zero or more" of them. The ampersand (&) denotes the entire match. There's no need to have parentheses around everything in this case. (The beginning-of-line anchor ^ is zero-width and doesn't matter here.)



                I removed the cat because it's unnecessary. I also removed your /g modifier because the ^ anchor means this can only match once per line, so you'll never get a second match and therefore a global replacement doesn't do anything.






                share|improve this answer















                Using GNU sed, you can invoke as sed -E or else you can escape the parentheses in order to get the back-reference working, but if you're not using GNU sed, you can't rely on back references; POSIX sed doesn't (yet) support the -E or -r argument for Extended Regular Expressions (ERE) nor does it support GNU's Basic Regular Expression (BRE) backslash notation. (Here's more on POSIX ERE & BRE, though it doesn't speak in much depth about GNU's BRE implementation allowing escaping into ERE functionality.)



                Fortunately, (in this case) you don't need ERE. This should work for you:





                sed 's/^[^A-Za-z0-9][^A-Za-z0-9]* /<ignore>&</ignore>/' file.ign


                BRE doesn't support the + quantifier, so I needed to double the nonword character set so it would be "one or more" by requiring "one" and then "zero or more" of them. The ampersand (&) denotes the entire match. There's no need to have parentheses around everything in this case. (The beginning-of-line anchor ^ is zero-width and doesn't matter here.)



                I removed the cat because it's unnecessary. I also removed your /g modifier because the ^ anchor means this can only match once per line, so you'll never get a second match and therefore a global replacement doesn't do anything.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Feb 8 at 15:27

























                answered Feb 7 at 16:31









                Adam KatzAdam Katz

                2,2501221




                2,2501221



























                    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%2f499185%2f1-not-defined-in-the-re%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

                    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?