trying to parse multiple patterns from single command (using sed)How do I parse command line arguments in Bash?Escape a string for a sed replace patternAssigning default values to shell variables with a single command in bashsed command with -i option failing on Mac, but works on LinuxHow to reload .bash_profile from the command line?Add line break to 'git commit -m' from the command linefind -exec with multiple commandsFind and replace in file and overwrite file doesn't work, it empties the fileHow to replace multiple patterns at once with sed?How to split a file which is delimited by bullet points

I caught several of my students plagiarizing. Could it be my fault as a teacher?

Can commander tax be proliferated?

Feels like I am getting dragged into office politics

How did Captain America use this power?

How could a planet have most of its water in the atmosphere?

Why is the SNP putting so much emphasis on currency plans?

If Earth is tilted, why is Polaris always above the same spot?

How to efficiently calculate prefix sum of frequencies of characters in a string?

Is it the same airport YUL and YMQ in Canada?

Has any spacecraft ever had the ability to directly communicate with civilian air traffic control?

Field Length Validation for Desktop Application which has maximum 1000 characters

How do I tell my manager that his code review comment is wrong?

How to creep the reader out with what seems like a normal person?

What word means "to make something obsolete"?

What happens if I start too many background jobs?

What was the state of the German rail system in 1944?

My ID is expired, can I fly to the Bahamas with my passport

Disabling Resource Governor in SQL Server

What is the most remote airport from the center of the city it supposedly serves?

What happened to Rhaegal?

What is the limiting factor for a CAN bus to exceed 1Mbps bandwidth?

Visa for volunteering in England

CRT Oscilloscope - part of the plot is missing

Any examples of headwear for races with animal ears?



trying to parse multiple patterns from single command (using sed)


How do I parse command line arguments in Bash?Escape a string for a sed replace patternAssigning default values to shell variables with a single command in bashsed command with -i option failing on Mac, but works on LinuxHow to reload .bash_profile from the command line?Add line break to 'git commit -m' from the command linefind -exec with multiple commandsFind and replace in file and overwrite file doesn't work, it empties the fileHow to replace multiple patterns at once with sed?How to split a file which is delimited by bullet points






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








2















I have multiple files (markdown) that are used to generate different artifacts. For one of the artifacts, I need to parse for lines that begin with # AND for lines between a pattern (::: notes -> :::).



example file



# Blah 

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.

- one
- two
- three

<!--
::: notes

- one is yadda yadda
- two is yadda yadda yadda
- three is wrong

:::
-->

## derp derp

Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

# woo hoo!

Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

<!--
::: notes

Aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

:::
-->


I can use sed to find all the # for me



sed -n '/#/p' FILENAME.md


produces the output:



# Blah 
## derp derp
# woo hoo!


and I can use sed to properly find and spit out the notes



sed -n '/::: notes/, /:::/p' FILENAME.md 


produces the output:



::: notes 

- one is yadda yadda
- two is yadda yadda yadda
- three is wrong

:::
::: notes

Aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

:::


But what I really need is the output in the right order (same order it appears in the file) like:



# Blah
::: notes

- one is yadda yadda
- two is yadda yadda yadda
- three is wrong

:::
## derp derp
# woo hoo!
::: notes

Aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

:::


Any sed guru's handy ?
Thanks in advance!!










share|improve this question






























    2















    I have multiple files (markdown) that are used to generate different artifacts. For one of the artifacts, I need to parse for lines that begin with # AND for lines between a pattern (::: notes -> :::).



    example file



    # Blah 

    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua.

    - one
    - two
    - three

    <!--
    ::: notes

    - one is yadda yadda
    - two is yadda yadda yadda
    - three is wrong

    :::
    -->

    ## derp derp

    Duis aute irure dolor in reprehenderit in voluptate velit esse
    cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
    proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

    # woo hoo!

    Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

    <!--
    ::: notes

    Aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
    cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
    proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

    :::
    -->


    I can use sed to find all the # for me



    sed -n '/#/p' FILENAME.md


    produces the output:



    # Blah 
    ## derp derp
    # woo hoo!


    and I can use sed to properly find and spit out the notes



    sed -n '/::: notes/, /:::/p' FILENAME.md 


    produces the output:



    ::: notes 

    - one is yadda yadda
    - two is yadda yadda yadda
    - three is wrong

    :::
    ::: notes

    Aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
    cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
    proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

    :::


    But what I really need is the output in the right order (same order it appears in the file) like:



    # Blah
    ::: notes

    - one is yadda yadda
    - two is yadda yadda yadda
    - three is wrong

    :::
    ## derp derp
    # woo hoo!
    ::: notes

    Aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
    cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
    proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

    :::


    Any sed guru's handy ?
    Thanks in advance!!










    share|improve this question


























      2












      2








      2








      I have multiple files (markdown) that are used to generate different artifacts. For one of the artifacts, I need to parse for lines that begin with # AND for lines between a pattern (::: notes -> :::).



      example file



      # Blah 

      Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
      tempor incididunt ut labore et dolore magna aliqua.

      - one
      - two
      - three

      <!--
      ::: notes

      - one is yadda yadda
      - two is yadda yadda yadda
      - three is wrong

      :::
      -->

      ## derp derp

      Duis aute irure dolor in reprehenderit in voluptate velit esse
      cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
      proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

      # woo hoo!

      Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

      <!--
      ::: notes

      Aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
      cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
      proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

      :::
      -->


      I can use sed to find all the # for me



      sed -n '/#/p' FILENAME.md


      produces the output:



      # Blah 
      ## derp derp
      # woo hoo!


      and I can use sed to properly find and spit out the notes



      sed -n '/::: notes/, /:::/p' FILENAME.md 


      produces the output:



      ::: notes 

      - one is yadda yadda
      - two is yadda yadda yadda
      - three is wrong

      :::
      ::: notes

      Aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
      cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
      proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

      :::


      But what I really need is the output in the right order (same order it appears in the file) like:



      # Blah
      ::: notes

      - one is yadda yadda
      - two is yadda yadda yadda
      - three is wrong

      :::
      ## derp derp
      # woo hoo!
      ::: notes

      Aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
      cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
      proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

      :::


      Any sed guru's handy ?
      Thanks in advance!!










      share|improve this question
















      I have multiple files (markdown) that are used to generate different artifacts. For one of the artifacts, I need to parse for lines that begin with # AND for lines between a pattern (::: notes -> :::).



      example file



      # Blah 

      Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
      tempor incididunt ut labore et dolore magna aliqua.

      - one
      - two
      - three

      <!--
      ::: notes

      - one is yadda yadda
      - two is yadda yadda yadda
      - three is wrong

      :::
      -->

      ## derp derp

      Duis aute irure dolor in reprehenderit in voluptate velit esse
      cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
      proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

      # woo hoo!

      Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

      <!--
      ::: notes

      Aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
      cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
      proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

      :::
      -->


      I can use sed to find all the # for me



      sed -n '/#/p' FILENAME.md


      produces the output:



      # Blah 
      ## derp derp
      # woo hoo!


      and I can use sed to properly find and spit out the notes



      sed -n '/::: notes/, /:::/p' FILENAME.md 


      produces the output:



      ::: notes 

      - one is yadda yadda
      - two is yadda yadda yadda
      - three is wrong

      :::
      ::: notes

      Aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
      cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
      proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

      :::


      But what I really need is the output in the right order (same order it appears in the file) like:



      # Blah
      ::: notes

      - one is yadda yadda
      - two is yadda yadda yadda
      - three is wrong

      :::
      ## derp derp
      # woo hoo!
      ::: notes

      Aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
      cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
      proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

      :::


      Any sed guru's handy ?
      Thanks in advance!!







      bash sed posix






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 22 at 20:28







      Robert French

















      asked Mar 22 at 20:19









      Robert FrenchRobert French

      625411




      625411






















          1 Answer
          1






          active

          oldest

          votes


















          2














          Multiple search patterns can be specified in this way:



          sed -e 'command' -e 'command' filename


          So your solution would look like this:



          sed -n -e '/::: notes/, /:::/p' -e '/#/p' FILENAME.md





          share|improve this answer


















          • 2





            Or you can use ; as command separator sed 'command1 ; command2' (but it does not work with all commands, ex. w or r)

            – Kamil Cuk
            Mar 22 at 21:21











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          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: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          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%2fstackoverflow.com%2fquestions%2f55307252%2ftrying-to-parse-multiple-patterns-from-single-command-using-sed%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          Multiple search patterns can be specified in this way:



          sed -e 'command' -e 'command' filename


          So your solution would look like this:



          sed -n -e '/::: notes/, /:::/p' -e '/#/p' FILENAME.md





          share|improve this answer


















          • 2





            Or you can use ; as command separator sed 'command1 ; command2' (but it does not work with all commands, ex. w or r)

            – Kamil Cuk
            Mar 22 at 21:21















          2














          Multiple search patterns can be specified in this way:



          sed -e 'command' -e 'command' filename


          So your solution would look like this:



          sed -n -e '/::: notes/, /:::/p' -e '/#/p' FILENAME.md





          share|improve this answer


















          • 2





            Or you can use ; as command separator sed 'command1 ; command2' (but it does not work with all commands, ex. w or r)

            – Kamil Cuk
            Mar 22 at 21:21













          2












          2








          2







          Multiple search patterns can be specified in this way:



          sed -e 'command' -e 'command' filename


          So your solution would look like this:



          sed -n -e '/::: notes/, /:::/p' -e '/#/p' FILENAME.md





          share|improve this answer













          Multiple search patterns can be specified in this way:



          sed -e 'command' -e 'command' filename


          So your solution would look like this:



          sed -n -e '/::: notes/, /:::/p' -e '/#/p' FILENAME.md






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 22 at 21:13









          LazyMammalLazyMammal

          1746




          1746







          • 2





            Or you can use ; as command separator sed 'command1 ; command2' (but it does not work with all commands, ex. w or r)

            – Kamil Cuk
            Mar 22 at 21:21












          • 2





            Or you can use ; as command separator sed 'command1 ; command2' (but it does not work with all commands, ex. w or r)

            – Kamil Cuk
            Mar 22 at 21:21







          2




          2





          Or you can use ; as command separator sed 'command1 ; command2' (but it does not work with all commands, ex. w or r)

          – Kamil Cuk
          Mar 22 at 21:21





          Or you can use ; as command separator sed 'command1 ; command2' (but it does not work with all commands, ex. w or r)

          – Kamil Cuk
          Mar 22 at 21:21



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • 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%2fstackoverflow.com%2fquestions%2f55307252%2ftrying-to-parse-multiple-patterns-from-single-command-using-sed%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

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript