Print between lines 7-13 who contain a certain string (awk script)

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











up vote
0
down vote

favorite












I am trying to write a script (.awk) that will print out lines that contain a certain string between lines 7-13. I have it partially working however it prints out all lines that contain the string rather than only between 7-13.



#!/usr/bin/awk -f
BEGIN (NR>=7) && (NR<=13)
/word/ print $0


It is probably a dumb mistake on my part however I have tried searching everywhere.



the output when running



script.awk filename


is all lines that contain the word :/










share|improve this question









New contributor




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























    up vote
    0
    down vote

    favorite












    I am trying to write a script (.awk) that will print out lines that contain a certain string between lines 7-13. I have it partially working however it prints out all lines that contain the string rather than only between 7-13.



    #!/usr/bin/awk -f
    BEGIN (NR>=7) && (NR<=13)
    /word/ print $0


    It is probably a dumb mistake on my part however I have tried searching everywhere.



    the output when running



    script.awk filename


    is all lines that contain the word :/










    share|improve this question









    New contributor




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





















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am trying to write a script (.awk) that will print out lines that contain a certain string between lines 7-13. I have it partially working however it prints out all lines that contain the string rather than only between 7-13.



      #!/usr/bin/awk -f
      BEGIN (NR>=7) && (NR<=13)
      /word/ print $0


      It is probably a dumb mistake on my part however I have tried searching everywhere.



      the output when running



      script.awk filename


      is all lines that contain the word :/










      share|improve this question









      New contributor




      SheepWaffle 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 write a script (.awk) that will print out lines that contain a certain string between lines 7-13. I have it partially working however it prints out all lines that contain the string rather than only between 7-13.



      #!/usr/bin/awk -f
      BEGIN (NR>=7) && (NR<=13)
      /word/ print $0


      It is probably a dumb mistake on my part however I have tried searching everywhere.



      the output when running



      script.awk filename


      is all lines that contain the word :/







      awk






      share|improve this question









      New contributor




      SheepWaffle 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




      SheepWaffle 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 4 mins ago









      Jeff Schaller

      34.6k952115




      34.6k952115






      New contributor




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









      asked 12 mins ago









      SheepWaffle

      1




      1




      New contributor




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





      New contributor





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






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




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          You've put the line restriction logic in the "BEGIN" block, which is executed before awk reads in any data. Move that logic to the main loop:



          NR >= 7 && NR <= 13 && /word/ print 


          ($0 is the default print argument, if none is given).





          share




















            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
            );



            );






            SheepWaffle 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%2f478561%2fprint-between-lines-7-13-who-contain-a-certain-string-awk-script%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
            0
            down vote













            You've put the line restriction logic in the "BEGIN" block, which is executed before awk reads in any data. Move that logic to the main loop:



            NR >= 7 && NR <= 13 && /word/ print 


            ($0 is the default print argument, if none is given).





            share
























              up vote
              0
              down vote













              You've put the line restriction logic in the "BEGIN" block, which is executed before awk reads in any data. Move that logic to the main loop:



              NR >= 7 && NR <= 13 && /word/ print 


              ($0 is the default print argument, if none is given).





              share






















                up vote
                0
                down vote










                up vote
                0
                down vote









                You've put the line restriction logic in the "BEGIN" block, which is executed before awk reads in any data. Move that logic to the main loop:



                NR >= 7 && NR <= 13 && /word/ print 


                ($0 is the default print argument, if none is given).





                share












                You've put the line restriction logic in the "BEGIN" block, which is executed before awk reads in any data. Move that logic to the main loop:



                NR >= 7 && NR <= 13 && /word/ print 


                ($0 is the default print argument, if none is given).






                share











                share


                share










                answered 4 mins ago









                Jeff Schaller

                34.6k952115




                34.6k952115




















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









                     

                    draft saved


                    draft discarded


















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












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











                    SheepWaffle 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%2f478561%2fprint-between-lines-7-13-who-contain-a-certain-string-awk-script%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?

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay