awk: print lines after match to end of file












4















I'm trying to parse a usage message like:



Usage:
docker-compose [-f <arg>...] [options] [COMMAND] [ARGS...]
docker-compose -h|--help
...
Commands:
build Build or rebuild services
bundle Generate a Docker bundle from the Compose file
...


to grab the Command names only. So I'm looking to skip all lines up to and including the Commands: line, then print the first word on all following lines, i.e.



  build
bundle
...


Currently I'm doing



docker-compose --help | sed -e '1,/Commands:/d' | awk '{ print $1 }'


and while this works, I suspect I could do the whole thing with a single awk. The closest I've got so far is:



docker-compose --help | awk '/Commands:/,0 { print $1 }'


But that includes the matched Commands: line. Can it be done?










share|improve this question





























    4















    I'm trying to parse a usage message like:



    Usage:
    docker-compose [-f <arg>...] [options] [COMMAND] [ARGS...]
    docker-compose -h|--help
    ...
    Commands:
    build Build or rebuild services
    bundle Generate a Docker bundle from the Compose file
    ...


    to grab the Command names only. So I'm looking to skip all lines up to and including the Commands: line, then print the first word on all following lines, i.e.



      build
    bundle
    ...


    Currently I'm doing



    docker-compose --help | sed -e '1,/Commands:/d' | awk '{ print $1 }'


    and while this works, I suspect I could do the whole thing with a single awk. The closest I've got so far is:



    docker-compose --help | awk '/Commands:/,0 { print $1 }'


    But that includes the matched Commands: line. Can it be done?










    share|improve this question



























      4












      4








      4








      I'm trying to parse a usage message like:



      Usage:
      docker-compose [-f <arg>...] [options] [COMMAND] [ARGS...]
      docker-compose -h|--help
      ...
      Commands:
      build Build or rebuild services
      bundle Generate a Docker bundle from the Compose file
      ...


      to grab the Command names only. So I'm looking to skip all lines up to and including the Commands: line, then print the first word on all following lines, i.e.



        build
      bundle
      ...


      Currently I'm doing



      docker-compose --help | sed -e '1,/Commands:/d' | awk '{ print $1 }'


      and while this works, I suspect I could do the whole thing with a single awk. The closest I've got so far is:



      docker-compose --help | awk '/Commands:/,0 { print $1 }'


      But that includes the matched Commands: line. Can it be done?










      share|improve this question
















      I'm trying to parse a usage message like:



      Usage:
      docker-compose [-f <arg>...] [options] [COMMAND] [ARGS...]
      docker-compose -h|--help
      ...
      Commands:
      build Build or rebuild services
      bundle Generate a Docker bundle from the Compose file
      ...


      to grab the Command names only. So I'm looking to skip all lines up to and including the Commands: line, then print the first word on all following lines, i.e.



        build
      bundle
      ...


      Currently I'm doing



      docker-compose --help | sed -e '1,/Commands:/d' | awk '{ print $1 }'


      and while this works, I suspect I could do the whole thing with a single awk. The closest I've got so far is:



      docker-compose --help | awk '/Commands:/,0 { print $1 }'


      But that includes the matched Commands: line. Can it be done?







      text-processing awk






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jun 20 '17 at 2:31









      Stephen Rauch

      3,344101428




      3,344101428










      asked Jun 20 '17 at 0:23









      ivanivan

      722719




      722719






















          3 Answers
          3






          active

          oldest

          votes


















          9














          If you mark the presence of your fence, then you can use it to decide to print the next line and after like:



          awk 'x==1 {print $1} /Commands:/ {x=1}'





          share|improve this answer


























          • This is great, thanks. It looks like I don't even need the ,0 anymore.

            – ivan
            Jun 20 '17 at 1:26






          • 1





            note that print $1 only prints the first word. use print or print $0 to print the whole line

            – Chris Maes
            Aug 29 '18 at 12:15



















          2














          Note that 1,/Commands:/d easily translates to awk like:



          awk 'NR==1, $1 == "Commands:" {next}; NF {print $1}'


          A difference with sed is that it will also work if Command: is on the first line.



          And the NF {print $1} can be translated to sed:



          sed -n '1,/^Commands:/!s/^[[:blank:]]*([^[:blank:]]{1,}).*/1/p'





          share|improve this answer































            0














            sed -n '/Commands:/,$p' filename | awk 'NR!=1{print $1}'





            share|improve this answer










            New contributor




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




















              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%2f372105%2fawk-print-lines-after-match-to-end-of-file%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              9














              If you mark the presence of your fence, then you can use it to decide to print the next line and after like:



              awk 'x==1 {print $1} /Commands:/ {x=1}'





              share|improve this answer


























              • This is great, thanks. It looks like I don't even need the ,0 anymore.

                – ivan
                Jun 20 '17 at 1:26






              • 1





                note that print $1 only prints the first word. use print or print $0 to print the whole line

                – Chris Maes
                Aug 29 '18 at 12:15
















              9














              If you mark the presence of your fence, then you can use it to decide to print the next line and after like:



              awk 'x==1 {print $1} /Commands:/ {x=1}'





              share|improve this answer


























              • This is great, thanks. It looks like I don't even need the ,0 anymore.

                – ivan
                Jun 20 '17 at 1:26






              • 1





                note that print $1 only prints the first word. use print or print $0 to print the whole line

                – Chris Maes
                Aug 29 '18 at 12:15














              9












              9








              9







              If you mark the presence of your fence, then you can use it to decide to print the next line and after like:



              awk 'x==1 {print $1} /Commands:/ {x=1}'





              share|improve this answer















              If you mark the presence of your fence, then you can use it to decide to print the next line and after like:



              awk 'x==1 {print $1} /Commands:/ {x=1}'






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Jun 20 '17 at 2:31

























              answered Jun 20 '17 at 0:43









              Stephen RauchStephen Rauch

              3,344101428




              3,344101428













              • This is great, thanks. It looks like I don't even need the ,0 anymore.

                – ivan
                Jun 20 '17 at 1:26






              • 1





                note that print $1 only prints the first word. use print or print $0 to print the whole line

                – Chris Maes
                Aug 29 '18 at 12:15



















              • This is great, thanks. It looks like I don't even need the ,0 anymore.

                – ivan
                Jun 20 '17 at 1:26






              • 1





                note that print $1 only prints the first word. use print or print $0 to print the whole line

                – Chris Maes
                Aug 29 '18 at 12:15

















              This is great, thanks. It looks like I don't even need the ,0 anymore.

              – ivan
              Jun 20 '17 at 1:26





              This is great, thanks. It looks like I don't even need the ,0 anymore.

              – ivan
              Jun 20 '17 at 1:26




              1




              1





              note that print $1 only prints the first word. use print or print $0 to print the whole line

              – Chris Maes
              Aug 29 '18 at 12:15





              note that print $1 only prints the first word. use print or print $0 to print the whole line

              – Chris Maes
              Aug 29 '18 at 12:15













              2














              Note that 1,/Commands:/d easily translates to awk like:



              awk 'NR==1, $1 == "Commands:" {next}; NF {print $1}'


              A difference with sed is that it will also work if Command: is on the first line.



              And the NF {print $1} can be translated to sed:



              sed -n '1,/^Commands:/!s/^[[:blank:]]*([^[:blank:]]{1,}).*/1/p'





              share|improve this answer




























                2














                Note that 1,/Commands:/d easily translates to awk like:



                awk 'NR==1, $1 == "Commands:" {next}; NF {print $1}'


                A difference with sed is that it will also work if Command: is on the first line.



                And the NF {print $1} can be translated to sed:



                sed -n '1,/^Commands:/!s/^[[:blank:]]*([^[:blank:]]{1,}).*/1/p'





                share|improve this answer


























                  2












                  2








                  2







                  Note that 1,/Commands:/d easily translates to awk like:



                  awk 'NR==1, $1 == "Commands:" {next}; NF {print $1}'


                  A difference with sed is that it will also work if Command: is on the first line.



                  And the NF {print $1} can be translated to sed:



                  sed -n '1,/^Commands:/!s/^[[:blank:]]*([^[:blank:]]{1,}).*/1/p'





                  share|improve this answer













                  Note that 1,/Commands:/d easily translates to awk like:



                  awk 'NR==1, $1 == "Commands:" {next}; NF {print $1}'


                  A difference with sed is that it will also work if Command: is on the first line.



                  And the NF {print $1} can be translated to sed:



                  sed -n '1,/^Commands:/!s/^[[:blank:]]*([^[:blank:]]{1,}).*/1/p'






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jun 20 '17 at 5:39









                  Stéphane ChazelasStéphane Chazelas

                  309k57582942




                  309k57582942























                      0














                      sed -n '/Commands:/,$p' filename | awk 'NR!=1{print $1}'





                      share|improve this answer










                      New contributor




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

























                        0














                        sed -n '/Commands:/,$p' filename | awk 'NR!=1{print $1}'





                        share|improve this answer










                        New contributor




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























                          0












                          0








                          0







                          sed -n '/Commands:/,$p' filename | awk 'NR!=1{print $1}'





                          share|improve this answer










                          New contributor




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










                          sed -n '/Commands:/,$p' filename | awk 'NR!=1{print $1}'






                          share|improve this answer










                          New contributor




                          Deepika Reddy Billuri 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 answer



                          share|improve this answer








                          edited 8 mins ago









                          Michael Mrozek

                          61.7k29192211




                          61.7k29192211






                          New contributor




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









                          answered 1 hour ago









                          Deepika Reddy BilluriDeepika Reddy Billuri

                          12




                          12




                          New contributor




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





                          New contributor





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






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






























                              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%2f372105%2fawk-print-lines-after-match-to-end-of-file%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 rewrite equation of hyperbola in standard form

                              No ethernet ip address in my vocore2