sed - include all found in between 2 pattern, except what's found between other patternsed lines after match...
What is the probability of a biased coin coming up heads given that a liar is claiming that the coin came up heads?
Why do cheap flights with a layover get more expensive when you split them up into separate flights?
Can attackers change the public key of certificate during the SSL handshake
How to check a file was encrypted (really & correctly)
Which genus do I use for neutral expressions in German?
What is an air conditioner compressor hard start kit and how does it work?
Does a 4 bladed prop have almost twice the thrust of a 2 bladed prop?
How to call made-up data?
Getting an entry level IT position later in life
Will a research paper be retracted if the code (which was made publically available ) is shown have a flaw in the logic?
In MTG, was there ever a five-color deck that worked well?
A verb for when some rights are not violated?
Can I enter a rental property without giving notice if I'm afraid a tenant may be hurt?
Launch capabilities of GSLV Mark III
What date did Henry Morgan capture his most famous flagship, the "Satisfaction"?
Is the first page of a novel really that important?
What was the role of Commodore-West Germany?
Why do scoped enums allow use of | operator when initializing using previously assigned values?
What are the function of EM and EN spaces?
What prevents ads from reading my password as I type it?
What does the ISO setting for mechanical 35mm film cameras actually do?
How can I perform a deterministic physics simulation?
What is it exactly about flying a Flyboard across the English channel that made Zapata's thighs burn?
Why should I "believe in" weak solutions to PDEs?
sed - include all found in between 2 pattern, except what's found between other pattern
sed lines after match and before next matchSearch for a string and print everything before and after within a rangeUsing sed / awk to change words between two patternsexcluding a character before a certain character in sedawk or sed to display output one per line based of search patternsed - if condition met, use next patternSed range problem if the last pattern is not metRegular expression used in sed not giving the desired result between intervalsfind: exclude n different directories and m different files present at any level but include few files from some excluded directoriesHow to delete string other than pattern?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I have a sed pattern search as below:
sed -n '/<centerline/,/</centerline/p'
This finds everything in between <centerline> and </centerline>
I want to ignore all the cases where I have <centerline id ="sid*" > till closing next </centerline>
Basically, I want to include all the centerlines except the case where centerline is sid.
Some of the snippets given below to be included:
<centerline id ="star12L" >
<polyline>
<point x="487610.06" y="2803975.46" />
<point x="501348.98" y="2795594.35" />
</polyline>
</centerline>
To exclude:
<centerline id ="sid12L" >
<polyline>
<point x="501348.98" y="2795594.35" />
<point x="487610.06" y="2803975.46" />
</polyline>
</centerline>
How can I do this?
Thanks!
linux shell-script shell awk sed
New contributor
user365840 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
I have a sed pattern search as below:
sed -n '/<centerline/,/</centerline/p'
This finds everything in between <centerline> and </centerline>
I want to ignore all the cases where I have <centerline id ="sid*" > till closing next </centerline>
Basically, I want to include all the centerlines except the case where centerline is sid.
Some of the snippets given below to be included:
<centerline id ="star12L" >
<polyline>
<point x="487610.06" y="2803975.46" />
<point x="501348.98" y="2795594.35" />
</polyline>
</centerline>
To exclude:
<centerline id ="sid12L" >
<polyline>
<point x="501348.98" y="2795594.35" />
<point x="487610.06" y="2803975.46" />
</polyline>
</centerline>
How can I do this?
Thanks!
linux shell-script shell awk sed
New contributor
user365840 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
If you are parsing XML, it would be a whole lot easier to do that with an XML parser, such asxmlstarlet.
– Kusalananda♦
1 hour ago
unfortunately, this is needed in sed as we want to process file through shell script.
– user365840
1 hour ago
You can call xmlstalet from a shell script just like you can call sed from a shell script. edit your question to include concise, testable sample input (including your target strings in-context) and expected output for us to be able to help you. Make sure to cover all your worst-case scenario use cases (nested target delimiters, multiple delimiters on a line, delimiters within comments, delimiters within strings, etc.).
– Ed Morton
1 hour ago
add a comment |
I have a sed pattern search as below:
sed -n '/<centerline/,/</centerline/p'
This finds everything in between <centerline> and </centerline>
I want to ignore all the cases where I have <centerline id ="sid*" > till closing next </centerline>
Basically, I want to include all the centerlines except the case where centerline is sid.
Some of the snippets given below to be included:
<centerline id ="star12L" >
<polyline>
<point x="487610.06" y="2803975.46" />
<point x="501348.98" y="2795594.35" />
</polyline>
</centerline>
To exclude:
<centerline id ="sid12L" >
<polyline>
<point x="501348.98" y="2795594.35" />
<point x="487610.06" y="2803975.46" />
</polyline>
</centerline>
How can I do this?
Thanks!
linux shell-script shell awk sed
New contributor
user365840 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I have a sed pattern search as below:
sed -n '/<centerline/,/</centerline/p'
This finds everything in between <centerline> and </centerline>
I want to ignore all the cases where I have <centerline id ="sid*" > till closing next </centerline>
Basically, I want to include all the centerlines except the case where centerline is sid.
Some of the snippets given below to be included:
<centerline id ="star12L" >
<polyline>
<point x="487610.06" y="2803975.46" />
<point x="501348.98" y="2795594.35" />
</polyline>
</centerline>
To exclude:
<centerline id ="sid12L" >
<polyline>
<point x="501348.98" y="2795594.35" />
<point x="487610.06" y="2803975.46" />
</polyline>
</centerline>
How can I do this?
Thanks!
linux shell-script shell awk sed
linux shell-script shell awk sed
New contributor
user365840 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
user365840 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 1 hour ago
user365840
New contributor
user365840 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 1 hour ago
user365840user365840
11 bronze badge
11 bronze badge
New contributor
user365840 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
user365840 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
If you are parsing XML, it would be a whole lot easier to do that with an XML parser, such asxmlstarlet.
– Kusalananda♦
1 hour ago
unfortunately, this is needed in sed as we want to process file through shell script.
– user365840
1 hour ago
You can call xmlstalet from a shell script just like you can call sed from a shell script. edit your question to include concise, testable sample input (including your target strings in-context) and expected output for us to be able to help you. Make sure to cover all your worst-case scenario use cases (nested target delimiters, multiple delimiters on a line, delimiters within comments, delimiters within strings, etc.).
– Ed Morton
1 hour ago
add a comment |
If you are parsing XML, it would be a whole lot easier to do that with an XML parser, such asxmlstarlet.
– Kusalananda♦
1 hour ago
unfortunately, this is needed in sed as we want to process file through shell script.
– user365840
1 hour ago
You can call xmlstalet from a shell script just like you can call sed from a shell script. edit your question to include concise, testable sample input (including your target strings in-context) and expected output for us to be able to help you. Make sure to cover all your worst-case scenario use cases (nested target delimiters, multiple delimiters on a line, delimiters within comments, delimiters within strings, etc.).
– Ed Morton
1 hour ago
If you are parsing XML, it would be a whole lot easier to do that with an XML parser, such as
xmlstarlet.– Kusalananda♦
1 hour ago
If you are parsing XML, it would be a whole lot easier to do that with an XML parser, such as
xmlstarlet.– Kusalananda♦
1 hour ago
unfortunately, this is needed in sed as we want to process file through shell script.
– user365840
1 hour ago
unfortunately, this is needed in sed as we want to process file through shell script.
– user365840
1 hour ago
You can call xmlstalet from a shell script just like you can call sed from a shell script. edit your question to include concise, testable sample input (including your target strings in-context) and expected output for us to be able to help you. Make sure to cover all your worst-case scenario use cases (nested target delimiters, multiple delimiters on a line, delimiters within comments, delimiters within strings, etc.).
– Ed Morton
1 hour ago
You can call xmlstalet from a shell script just like you can call sed from a shell script. edit your question to include concise, testable sample input (including your target strings in-context) and expected output for us to be able to help you. Make sure to cover all your worst-case scenario use cases (nested target delimiters, multiple delimiters on a line, delimiters within comments, delimiters within strings, etc.).
– Ed Morton
1 hour ago
add a comment |
1 Answer
1
active
oldest
votes
Assuming the XML file looks something like
<?xml version="1.0"?>
<root>
<centerline>get this</centerline>
<centerline id="sid*">not this</centerline>
<centerline id="somethingelse" id2="why not?">more here</centerline>
</root>
XMLStarlet would be able to parse out the two strings get this and more here (i.e., ignore the not this string) with
$ xmlstarlet sel -t -v '//centerline[boolean(@id) = false or @id != "sid*"]' -nl file.xml
get this
more here
The XPATH query //centerline[boolean(@id) = false or @id != "sid*"] means "match every centerline node that lacks an id attribute, or whose id attribute is not sid*, anywhere in the document".
If the data that you extract contains escaped characters (such as &), you can unescape these by piping the output of the above command through xmlstarlet unesc.
add a comment |
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
});
}
});
user365840 is a new contributor. Be nice, and check out our Code of Conduct.
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%2funix.stackexchange.com%2fquestions%2f534244%2fsed-include-all-found-in-between-2-pattern-except-whats-found-between-other%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
Assuming the XML file looks something like
<?xml version="1.0"?>
<root>
<centerline>get this</centerline>
<centerline id="sid*">not this</centerline>
<centerline id="somethingelse" id2="why not?">more here</centerline>
</root>
XMLStarlet would be able to parse out the two strings get this and more here (i.e., ignore the not this string) with
$ xmlstarlet sel -t -v '//centerline[boolean(@id) = false or @id != "sid*"]' -nl file.xml
get this
more here
The XPATH query //centerline[boolean(@id) = false or @id != "sid*"] means "match every centerline node that lacks an id attribute, or whose id attribute is not sid*, anywhere in the document".
If the data that you extract contains escaped characters (such as &), you can unescape these by piping the output of the above command through xmlstarlet unesc.
add a comment |
Assuming the XML file looks something like
<?xml version="1.0"?>
<root>
<centerline>get this</centerline>
<centerline id="sid*">not this</centerline>
<centerline id="somethingelse" id2="why not?">more here</centerline>
</root>
XMLStarlet would be able to parse out the two strings get this and more here (i.e., ignore the not this string) with
$ xmlstarlet sel -t -v '//centerline[boolean(@id) = false or @id != "sid*"]' -nl file.xml
get this
more here
The XPATH query //centerline[boolean(@id) = false or @id != "sid*"] means "match every centerline node that lacks an id attribute, or whose id attribute is not sid*, anywhere in the document".
If the data that you extract contains escaped characters (such as &), you can unescape these by piping the output of the above command through xmlstarlet unesc.
add a comment |
Assuming the XML file looks something like
<?xml version="1.0"?>
<root>
<centerline>get this</centerline>
<centerline id="sid*">not this</centerline>
<centerline id="somethingelse" id2="why not?">more here</centerline>
</root>
XMLStarlet would be able to parse out the two strings get this and more here (i.e., ignore the not this string) with
$ xmlstarlet sel -t -v '//centerline[boolean(@id) = false or @id != "sid*"]' -nl file.xml
get this
more here
The XPATH query //centerline[boolean(@id) = false or @id != "sid*"] means "match every centerline node that lacks an id attribute, or whose id attribute is not sid*, anywhere in the document".
If the data that you extract contains escaped characters (such as &), you can unescape these by piping the output of the above command through xmlstarlet unesc.
Assuming the XML file looks something like
<?xml version="1.0"?>
<root>
<centerline>get this</centerline>
<centerline id="sid*">not this</centerline>
<centerline id="somethingelse" id2="why not?">more here</centerline>
</root>
XMLStarlet would be able to parse out the two strings get this and more here (i.e., ignore the not this string) with
$ xmlstarlet sel -t -v '//centerline[boolean(@id) = false or @id != "sid*"]' -nl file.xml
get this
more here
The XPATH query //centerline[boolean(@id) = false or @id != "sid*"] means "match every centerline node that lacks an id attribute, or whose id attribute is not sid*, anywhere in the document".
If the data that you extract contains escaped characters (such as &), you can unescape these by piping the output of the above command through xmlstarlet unesc.
edited 1 hour ago
answered 1 hour ago
Kusalananda♦Kusalananda
158k18 gold badges313 silver badges498 bronze badges
158k18 gold badges313 silver badges498 bronze badges
add a comment |
add a comment |
user365840 is a new contributor. Be nice, and check out our Code of Conduct.
user365840 is a new contributor. Be nice, and check out our Code of Conduct.
user365840 is a new contributor. Be nice, and check out our Code of Conduct.
user365840 is a new contributor. Be nice, and check out our Code of Conduct.
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.
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%2funix.stackexchange.com%2fquestions%2f534244%2fsed-include-all-found-in-between-2-pattern-except-whats-found-between-other%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
If you are parsing XML, it would be a whole lot easier to do that with an XML parser, such as
xmlstarlet.– Kusalananda♦
1 hour ago
unfortunately, this is needed in sed as we want to process file through shell script.
– user365840
1 hour ago
You can call xmlstalet from a shell script just like you can call sed from a shell script. edit your question to include concise, testable sample input (including your target strings in-context) and expected output for us to be able to help you. Make sure to cover all your worst-case scenario use cases (nested target delimiters, multiple delimiters on a line, delimiters within comments, delimiters within strings, etc.).
– Ed Morton
1 hour ago