awk to find the multiple pattern in a line

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











up vote
1
down vote

favorite












I have file file1.txt /file2.txt When I run the awk command with boundary search between "Type header call_header " and "END" it print the lines below END also .
Example :-



File1.txt



Type header call_header 
abc , def , ghi ,
jkl ,mno
END
Define call_header
type as call_header


Fil2.txt



Type head call_header
data1, data2, voice ,
mms , mms2
END
Define call_header
type as call_header


I have tried:



awk '/^Type (header|head) call_header$/,/^END?$/' print file1.txt


However, it is printing other lines also .



Need Below data only :



Type header call_header 
abc , def , ghi ,
jkl ,mno
END






share|improve this question


























    up vote
    1
    down vote

    favorite












    I have file file1.txt /file2.txt When I run the awk command with boundary search between "Type header call_header " and "END" it print the lines below END also .
    Example :-



    File1.txt



    Type header call_header 
    abc , def , ghi ,
    jkl ,mno
    END
    Define call_header
    type as call_header


    Fil2.txt



    Type head call_header
    data1, data2, voice ,
    mms , mms2
    END
    Define call_header
    type as call_header


    I have tried:



    awk '/^Type (header|head) call_header$/,/^END?$/' print file1.txt


    However, it is printing other lines also .



    Need Below data only :



    Type header call_header 
    abc , def , ghi ,
    jkl ,mno
    END






    share|improve this question
























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have file file1.txt /file2.txt When I run the awk command with boundary search between "Type header call_header " and "END" it print the lines below END also .
      Example :-



      File1.txt



      Type header call_header 
      abc , def , ghi ,
      jkl ,mno
      END
      Define call_header
      type as call_header


      Fil2.txt



      Type head call_header
      data1, data2, voice ,
      mms , mms2
      END
      Define call_header
      type as call_header


      I have tried:



      awk '/^Type (header|head) call_header$/,/^END?$/' print file1.txt


      However, it is printing other lines also .



      Need Below data only :



      Type header call_header 
      abc , def , ghi ,
      jkl ,mno
      END






      share|improve this question














      I have file file1.txt /file2.txt When I run the awk command with boundary search between "Type header call_header " and "END" it print the lines below END also .
      Example :-



      File1.txt



      Type header call_header 
      abc , def , ghi ,
      jkl ,mno
      END
      Define call_header
      type as call_header


      Fil2.txt



      Type head call_header
      data1, data2, voice ,
      mms , mms2
      END
      Define call_header
      type as call_header


      I have tried:



      awk '/^Type (header|head) call_header$/,/^END?$/' print file1.txt


      However, it is printing other lines also .



      Need Below data only :



      Type header call_header 
      abc , def , ghi ,
      jkl ,mno
      END








      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 22 at 18:56









      Kusalananda

      103k13202319




      103k13202319










      asked Jan 22 at 18:46









      isha

      113




      113




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote













          Your awk invocation is incorrect:



          awk '/^Type (header|head) call_header$/,/^END?$/' print file1.txt


          Here, awk would search for a file called print.



          The whole script should be within the single quotes:



          awk '/^Type (header|head) call_header$/,/^END?$/ print' file1.txt


          Or, alternatively (shortening the first regular expression slightly and getting rid of print completely),



          awk '/^Type head(er)? call_header$/,/^END?$/' file1.txt


          Tested with OpenBSD awk, mawk and GNU awk.



          With sed, this is remarkably similar to the above:



          sed -nr '/^Type head(er)? call_header$/,/^END?$/p' file1.txt





          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: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            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%2f418923%2fawk-to-find-the-multiple-pattern-in-a-line%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            2
            down vote













            Your awk invocation is incorrect:



            awk '/^Type (header|head) call_header$/,/^END?$/' print file1.txt


            Here, awk would search for a file called print.



            The whole script should be within the single quotes:



            awk '/^Type (header|head) call_header$/,/^END?$/ print' file1.txt


            Or, alternatively (shortening the first regular expression slightly and getting rid of print completely),



            awk '/^Type head(er)? call_header$/,/^END?$/' file1.txt


            Tested with OpenBSD awk, mawk and GNU awk.



            With sed, this is remarkably similar to the above:



            sed -nr '/^Type head(er)? call_header$/,/^END?$/p' file1.txt





            share|improve this answer
























              up vote
              2
              down vote













              Your awk invocation is incorrect:



              awk '/^Type (header|head) call_header$/,/^END?$/' print file1.txt


              Here, awk would search for a file called print.



              The whole script should be within the single quotes:



              awk '/^Type (header|head) call_header$/,/^END?$/ print' file1.txt


              Or, alternatively (shortening the first regular expression slightly and getting rid of print completely),



              awk '/^Type head(er)? call_header$/,/^END?$/' file1.txt


              Tested with OpenBSD awk, mawk and GNU awk.



              With sed, this is remarkably similar to the above:



              sed -nr '/^Type head(er)? call_header$/,/^END?$/p' file1.txt





              share|improve this answer






















                up vote
                2
                down vote










                up vote
                2
                down vote









                Your awk invocation is incorrect:



                awk '/^Type (header|head) call_header$/,/^END?$/' print file1.txt


                Here, awk would search for a file called print.



                The whole script should be within the single quotes:



                awk '/^Type (header|head) call_header$/,/^END?$/ print' file1.txt


                Or, alternatively (shortening the first regular expression slightly and getting rid of print completely),



                awk '/^Type head(er)? call_header$/,/^END?$/' file1.txt


                Tested with OpenBSD awk, mawk and GNU awk.



                With sed, this is remarkably similar to the above:



                sed -nr '/^Type head(er)? call_header$/,/^END?$/p' file1.txt





                share|improve this answer












                Your awk invocation is incorrect:



                awk '/^Type (header|head) call_header$/,/^END?$/' print file1.txt


                Here, awk would search for a file called print.



                The whole script should be within the single quotes:



                awk '/^Type (header|head) call_header$/,/^END?$/ print' file1.txt


                Or, alternatively (shortening the first regular expression slightly and getting rid of print completely),



                awk '/^Type head(er)? call_header$/,/^END?$/' file1.txt


                Tested with OpenBSD awk, mawk and GNU awk.



                With sed, this is remarkably similar to the above:



                sed -nr '/^Type head(er)? call_header$/,/^END?$/p' file1.txt






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 22 at 18:52









                Kusalananda

                103k13202319




                103k13202319






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f418923%2fawk-to-find-the-multiple-pattern-in-a-line%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    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?