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;
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
add a comment |
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
add a comment |
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
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
bash sed posix
edited Mar 22 at 20:28
Robert French
asked Mar 22 at 20:19
Robert FrenchRobert French
625411
625411
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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
2
Or you can use;
as command separatorsed 'command1 ; command2'
(but it does not work with all commands, ex.w
orr
)
– Kamil Cuk
Mar 22 at 21:21
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
2
Or you can use;
as command separatorsed 'command1 ; command2'
(but it does not work with all commands, ex.w
orr
)
– Kamil Cuk
Mar 22 at 21:21
add a comment |
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
2
Or you can use;
as command separatorsed 'command1 ; command2'
(but it does not work with all commands, ex.w
orr
)
– Kamil Cuk
Mar 22 at 21:21
add a comment |
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
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
answered Mar 22 at 21:13
LazyMammalLazyMammal
1746
1746
2
Or you can use;
as command separatorsed 'command1 ; command2'
(but it does not work with all commands, ex.w
orr
)
– Kamil Cuk
Mar 22 at 21:21
add a comment |
2
Or you can use;
as command separatorsed 'command1 ; command2'
(but it does not work with all commands, ex.w
orr
)
– 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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