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!!
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