sed to delete lines using multiple search string

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











up vote
4
down vote

favorite












I have a text file, let say test1.txt, I need to remove the line containing dog and date with "29-APR-2015"



Using the below command to accomplish it but it is not deleting the lines.



Where as if i mention just with /DOG/d it is deleting the lines containing DOG.



command file (sedcommands)



/DOG,29-APR-2015/d


test1.txt



DOG 29-APR-2015 
DOG 29-APR-2015
DOG 30-APR-2015
CAT 29-APR-2015
CAT 29-APR-2015


command



sed -f sedcommands test1.txt > test2.txt









share|improve this question



























    up vote
    4
    down vote

    favorite












    I have a text file, let say test1.txt, I need to remove the line containing dog and date with "29-APR-2015"



    Using the below command to accomplish it but it is not deleting the lines.



    Where as if i mention just with /DOG/d it is deleting the lines containing DOG.



    command file (sedcommands)



    /DOG,29-APR-2015/d


    test1.txt



    DOG 29-APR-2015 
    DOG 29-APR-2015
    DOG 30-APR-2015
    CAT 29-APR-2015
    CAT 29-APR-2015


    command



    sed -f sedcommands test1.txt > test2.txt









    share|improve this question

























      up vote
      4
      down vote

      favorite









      up vote
      4
      down vote

      favorite











      I have a text file, let say test1.txt, I need to remove the line containing dog and date with "29-APR-2015"



      Using the below command to accomplish it but it is not deleting the lines.



      Where as if i mention just with /DOG/d it is deleting the lines containing DOG.



      command file (sedcommands)



      /DOG,29-APR-2015/d


      test1.txt



      DOG 29-APR-2015 
      DOG 29-APR-2015
      DOG 30-APR-2015
      CAT 29-APR-2015
      CAT 29-APR-2015


      command



      sed -f sedcommands test1.txt > test2.txt









      share|improve this question















      I have a text file, let say test1.txt, I need to remove the line containing dog and date with "29-APR-2015"



      Using the below command to accomplish it but it is not deleting the lines.



      Where as if i mention just with /DOG/d it is deleting the lines containing DOG.



      command file (sedcommands)



      /DOG,29-APR-2015/d


      test1.txt



      DOG 29-APR-2015 
      DOG 29-APR-2015
      DOG 30-APR-2015
      CAT 29-APR-2015
      CAT 29-APR-2015


      command



      sed -f sedcommands test1.txt > test2.txt






      sed






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 20 at 22:28









      Rui F Ribeiro

      38.2k1475125




      38.2k1475125










      asked Apr 29 '15 at 2:33









      Gopal

      12313




      12313




















          4 Answers
          4






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          With GNU sed:



          sed '/DOG//29-APR-2015/d' test1


          This method allows for any order. ie. DOG can either be before or after the date.






          share|improve this answer






















          • @cuonglm - sed --posix '/DOG//29-APR-2015/d' works fine in GNU sed version 4.2.1 (with all GNU extensions disabled).
            – Peter.O
            Apr 30 '15 at 4:11










          • @Peter.O: No, POSIX require terminator between the command anh }. At least your command won't work in BSD sed.
            – cuonglm
            Apr 30 '15 at 4:28










          • @Peter.O, GNU sed's --posix is to tell it to be more POSIX conformant. It's not telling it to report an error on any non-POSIX code you throw at it. It would not make GNU sed more POSIX conformant to report an error when you give it that non-standard xxx code.
            – Stéphane Chazelas
            May 4 '15 at 16:25


















          up vote
          3
          down vote













          POSIXly:



          sed -e '/DOG/!b' -e '/29-APR-2015/!b' -e d file


          branch to the end if you don't provide any label.



          or:



          sed '/DOG//29-APR-2015/d
          ' file


          Modern sed implementations also support command; form, this's an accepted extension by POSIX, but not required:



          sed '/DOG//29-APR-2015/d;' file





          share|improve this answer





























            up vote
            2
            down vote













            /DOG,29-APR-2015/d will not work because there is no comma between DOG and 9-APR-2015. Try this;



            $ sed -e '/DOG[[:space:]]*29-APR-2015/d' test1.txt 
            DOG 30-APR-2015
            CAT 29-APR-2015
            CAT 29-APR-2015


            [[:space:]]* allows for zero or more white space characters between DOG and 9-APR-2015. The character class [:space:] allows both ordinary spaces and tabs and is safe to use with unicode fonts.






            share|improve this answer



























              up vote
              1
              down vote













              The command file should contain:



              /DOG *29-APR-2015/d


              That is, DOG followed by 0 or more spaces, followed by specified date.






              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',
                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%2f199279%2fsed-to-delete-lines-using-multiple-search-string%23new-answer', 'question_page');

                );

                Post as a guest















                Required, but never shown

























                4 Answers
                4






                active

                oldest

                votes








                4 Answers
                4






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes








                up vote
                4
                down vote



                accepted










                With GNU sed:



                sed '/DOG//29-APR-2015/d' test1


                This method allows for any order. ie. DOG can either be before or after the date.






                share|improve this answer






















                • @cuonglm - sed --posix '/DOG//29-APR-2015/d' works fine in GNU sed version 4.2.1 (with all GNU extensions disabled).
                  – Peter.O
                  Apr 30 '15 at 4:11










                • @Peter.O: No, POSIX require terminator between the command anh }. At least your command won't work in BSD sed.
                  – cuonglm
                  Apr 30 '15 at 4:28










                • @Peter.O, GNU sed's --posix is to tell it to be more POSIX conformant. It's not telling it to report an error on any non-POSIX code you throw at it. It would not make GNU sed more POSIX conformant to report an error when you give it that non-standard xxx code.
                  – Stéphane Chazelas
                  May 4 '15 at 16:25















                up vote
                4
                down vote



                accepted










                With GNU sed:



                sed '/DOG//29-APR-2015/d' test1


                This method allows for any order. ie. DOG can either be before or after the date.






                share|improve this answer






















                • @cuonglm - sed --posix '/DOG//29-APR-2015/d' works fine in GNU sed version 4.2.1 (with all GNU extensions disabled).
                  – Peter.O
                  Apr 30 '15 at 4:11










                • @Peter.O: No, POSIX require terminator between the command anh }. At least your command won't work in BSD sed.
                  – cuonglm
                  Apr 30 '15 at 4:28










                • @Peter.O, GNU sed's --posix is to tell it to be more POSIX conformant. It's not telling it to report an error on any non-POSIX code you throw at it. It would not make GNU sed more POSIX conformant to report an error when you give it that non-standard xxx code.
                  – Stéphane Chazelas
                  May 4 '15 at 16:25













                up vote
                4
                down vote



                accepted







                up vote
                4
                down vote



                accepted






                With GNU sed:



                sed '/DOG//29-APR-2015/d' test1


                This method allows for any order. ie. DOG can either be before or after the date.






                share|improve this answer














                With GNU sed:



                sed '/DOG//29-APR-2015/d' test1


                This method allows for any order. ie. DOG can either be before or after the date.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Apr 29 '15 at 14:23









                cuonglm

                101k23196297




                101k23196297










                answered Apr 29 '15 at 3:17









                Peter.O

                18.7k1791143




                18.7k1791143











                • @cuonglm - sed --posix '/DOG//29-APR-2015/d' works fine in GNU sed version 4.2.1 (with all GNU extensions disabled).
                  – Peter.O
                  Apr 30 '15 at 4:11










                • @Peter.O: No, POSIX require terminator between the command anh }. At least your command won't work in BSD sed.
                  – cuonglm
                  Apr 30 '15 at 4:28










                • @Peter.O, GNU sed's --posix is to tell it to be more POSIX conformant. It's not telling it to report an error on any non-POSIX code you throw at it. It would not make GNU sed more POSIX conformant to report an error when you give it that non-standard xxx code.
                  – Stéphane Chazelas
                  May 4 '15 at 16:25

















                • @cuonglm - sed --posix '/DOG//29-APR-2015/d' works fine in GNU sed version 4.2.1 (with all GNU extensions disabled).
                  – Peter.O
                  Apr 30 '15 at 4:11










                • @Peter.O: No, POSIX require terminator between the command anh }. At least your command won't work in BSD sed.
                  – cuonglm
                  Apr 30 '15 at 4:28










                • @Peter.O, GNU sed's --posix is to tell it to be more POSIX conformant. It's not telling it to report an error on any non-POSIX code you throw at it. It would not make GNU sed more POSIX conformant to report an error when you give it that non-standard xxx code.
                  – Stéphane Chazelas
                  May 4 '15 at 16:25
















                @cuonglm - sed --posix '/DOG//29-APR-2015/d' works fine in GNU sed version 4.2.1 (with all GNU extensions disabled).
                – Peter.O
                Apr 30 '15 at 4:11




                @cuonglm - sed --posix '/DOG//29-APR-2015/d' works fine in GNU sed version 4.2.1 (with all GNU extensions disabled).
                – Peter.O
                Apr 30 '15 at 4:11












                @Peter.O: No, POSIX require terminator between the command anh }. At least your command won't work in BSD sed.
                – cuonglm
                Apr 30 '15 at 4:28




                @Peter.O: No, POSIX require terminator between the command anh }. At least your command won't work in BSD sed.
                – cuonglm
                Apr 30 '15 at 4:28












                @Peter.O, GNU sed's --posix is to tell it to be more POSIX conformant. It's not telling it to report an error on any non-POSIX code you throw at it. It would not make GNU sed more POSIX conformant to report an error when you give it that non-standard xxx code.
                – Stéphane Chazelas
                May 4 '15 at 16:25





                @Peter.O, GNU sed's --posix is to tell it to be more POSIX conformant. It's not telling it to report an error on any non-POSIX code you throw at it. It would not make GNU sed more POSIX conformant to report an error when you give it that non-standard xxx code.
                – Stéphane Chazelas
                May 4 '15 at 16:25













                up vote
                3
                down vote













                POSIXly:



                sed -e '/DOG/!b' -e '/29-APR-2015/!b' -e d file


                branch to the end if you don't provide any label.



                or:



                sed '/DOG//29-APR-2015/d
                ' file


                Modern sed implementations also support command; form, this's an accepted extension by POSIX, but not required:



                sed '/DOG//29-APR-2015/d;' file





                share|improve this answer


























                  up vote
                  3
                  down vote













                  POSIXly:



                  sed -e '/DOG/!b' -e '/29-APR-2015/!b' -e d file


                  branch to the end if you don't provide any label.



                  or:



                  sed '/DOG//29-APR-2015/d
                  ' file


                  Modern sed implementations also support command; form, this's an accepted extension by POSIX, but not required:



                  sed '/DOG//29-APR-2015/d;' file





                  share|improve this answer
























                    up vote
                    3
                    down vote










                    up vote
                    3
                    down vote









                    POSIXly:



                    sed -e '/DOG/!b' -e '/29-APR-2015/!b' -e d file


                    branch to the end if you don't provide any label.



                    or:



                    sed '/DOG//29-APR-2015/d
                    ' file


                    Modern sed implementations also support command; form, this's an accepted extension by POSIX, but not required:



                    sed '/DOG//29-APR-2015/d;' file





                    share|improve this answer














                    POSIXly:



                    sed -e '/DOG/!b' -e '/29-APR-2015/!b' -e d file


                    branch to the end if you don't provide any label.



                    or:



                    sed '/DOG//29-APR-2015/d
                    ' file


                    Modern sed implementations also support command; form, this's an accepted extension by POSIX, but not required:



                    sed '/DOG//29-APR-2015/d;' file






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited May 4 '15 at 17:04

























                    answered Apr 29 '15 at 4:46









                    cuonglm

                    101k23196297




                    101k23196297




















                        up vote
                        2
                        down vote













                        /DOG,29-APR-2015/d will not work because there is no comma between DOG and 9-APR-2015. Try this;



                        $ sed -e '/DOG[[:space:]]*29-APR-2015/d' test1.txt 
                        DOG 30-APR-2015
                        CAT 29-APR-2015
                        CAT 29-APR-2015


                        [[:space:]]* allows for zero or more white space characters between DOG and 9-APR-2015. The character class [:space:] allows both ordinary spaces and tabs and is safe to use with unicode fonts.






                        share|improve this answer
























                          up vote
                          2
                          down vote













                          /DOG,29-APR-2015/d will not work because there is no comma between DOG and 9-APR-2015. Try this;



                          $ sed -e '/DOG[[:space:]]*29-APR-2015/d' test1.txt 
                          DOG 30-APR-2015
                          CAT 29-APR-2015
                          CAT 29-APR-2015


                          [[:space:]]* allows for zero or more white space characters between DOG and 9-APR-2015. The character class [:space:] allows both ordinary spaces and tabs and is safe to use with unicode fonts.






                          share|improve this answer






















                            up vote
                            2
                            down vote










                            up vote
                            2
                            down vote









                            /DOG,29-APR-2015/d will not work because there is no comma between DOG and 9-APR-2015. Try this;



                            $ sed -e '/DOG[[:space:]]*29-APR-2015/d' test1.txt 
                            DOG 30-APR-2015
                            CAT 29-APR-2015
                            CAT 29-APR-2015


                            [[:space:]]* allows for zero or more white space characters between DOG and 9-APR-2015. The character class [:space:] allows both ordinary spaces and tabs and is safe to use with unicode fonts.






                            share|improve this answer












                            /DOG,29-APR-2015/d will not work because there is no comma between DOG and 9-APR-2015. Try this;



                            $ sed -e '/DOG[[:space:]]*29-APR-2015/d' test1.txt 
                            DOG 30-APR-2015
                            CAT 29-APR-2015
                            CAT 29-APR-2015


                            [[:space:]]* allows for zero or more white space characters between DOG and 9-APR-2015. The character class [:space:] allows both ordinary spaces and tabs and is safe to use with unicode fonts.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Apr 29 '15 at 2:41









                            John1024

                            45.4k4101118




                            45.4k4101118




















                                up vote
                                1
                                down vote













                                The command file should contain:



                                /DOG *29-APR-2015/d


                                That is, DOG followed by 0 or more spaces, followed by specified date.






                                share|improve this answer
























                                  up vote
                                  1
                                  down vote













                                  The command file should contain:



                                  /DOG *29-APR-2015/d


                                  That is, DOG followed by 0 or more spaces, followed by specified date.






                                  share|improve this answer






















                                    up vote
                                    1
                                    down vote










                                    up vote
                                    1
                                    down vote









                                    The command file should contain:



                                    /DOG *29-APR-2015/d


                                    That is, DOG followed by 0 or more spaces, followed by specified date.






                                    share|improve this answer












                                    The command file should contain:



                                    /DOG *29-APR-2015/d


                                    That is, DOG followed by 0 or more spaces, followed by specified date.







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Apr 29 '15 at 2:40









                                    unxnut

                                    3,5522918




                                    3,5522918



























                                         

                                        draft saved


                                        draft discarded















































                                         


                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f199279%2fsed-to-delete-lines-using-multiple-search-string%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?

                                        Bahrain

                                        Postfix configuration issue with fips on centos 7; mailgun relay