Extract content between tags which is having sub tag

Clash Royale CLAN TAG#URR8PPP
Extract the desired content from the file using "xmlstarlet" or "sed" or "awk" or some similar tool.
The process should refer the full name of the particular businessprocesses and then should just extract content in between that particular business process.
File from where the content to be extracted.
<businessProcesses>
<fullName>Customer Support</fullName>
<description>Use for Customer Support, TDG and Port</description>
<isActive>true</isActive>
<values>
<fullName>Action Item</fullName>
<default>false</default>
</values>
<values>
<fullName>Solved</fullName>
<default>false</default>
</values>
</businessProcesses>
<businessProcesses>
<fullName>Customer Support - Port</fullName>
<description>Telecom team use only</description>
<isActive>true</isActive>
<values>
<fullName>New</fullName>
<default>true</default>
</values>
<values>
<fullName>Open</fullName>
<default>false</default>
</values>
</businessProcesses>
</CustomObject>
Required output.
<businessProcesses>
<fullName>Customer Support - Port</fullName>
<description>Telecom team use only</description>
<isActive>true</isActive>
<values>
<fullName>New</fullName>
<default>true</default>
</values>
<values>
<fullName>Open</fullName>
<default>false</default>
</values>
</businessProcesses>
sed xml xmlstarlet
add a comment |
Extract the desired content from the file using "xmlstarlet" or "sed" or "awk" or some similar tool.
The process should refer the full name of the particular businessprocesses and then should just extract content in between that particular business process.
File from where the content to be extracted.
<businessProcesses>
<fullName>Customer Support</fullName>
<description>Use for Customer Support, TDG and Port</description>
<isActive>true</isActive>
<values>
<fullName>Action Item</fullName>
<default>false</default>
</values>
<values>
<fullName>Solved</fullName>
<default>false</default>
</values>
</businessProcesses>
<businessProcesses>
<fullName>Customer Support - Port</fullName>
<description>Telecom team use only</description>
<isActive>true</isActive>
<values>
<fullName>New</fullName>
<default>true</default>
</values>
<values>
<fullName>Open</fullName>
<default>false</default>
</values>
</businessProcesses>
</CustomObject>
Required output.
<businessProcesses>
<fullName>Customer Support - Port</fullName>
<description>Telecom team use only</description>
<isActive>true</isActive>
<values>
<fullName>New</fullName>
<default>true</default>
</values>
<values>
<fullName>Open</fullName>
<default>false</default>
</values>
</businessProcesses>
sed xml xmlstarlet
1
When you post your homework, you should at least provide enough information to solve the problem and look at basic formatting rules.
– Ljm Dullaart
Jan 24 at 18:46
2
What research have you made to solve this yourself?
– glenn jackman
Jan 24 at 19:09
add a comment |
Extract the desired content from the file using "xmlstarlet" or "sed" or "awk" or some similar tool.
The process should refer the full name of the particular businessprocesses and then should just extract content in between that particular business process.
File from where the content to be extracted.
<businessProcesses>
<fullName>Customer Support</fullName>
<description>Use for Customer Support, TDG and Port</description>
<isActive>true</isActive>
<values>
<fullName>Action Item</fullName>
<default>false</default>
</values>
<values>
<fullName>Solved</fullName>
<default>false</default>
</values>
</businessProcesses>
<businessProcesses>
<fullName>Customer Support - Port</fullName>
<description>Telecom team use only</description>
<isActive>true</isActive>
<values>
<fullName>New</fullName>
<default>true</default>
</values>
<values>
<fullName>Open</fullName>
<default>false</default>
</values>
</businessProcesses>
</CustomObject>
Required output.
<businessProcesses>
<fullName>Customer Support - Port</fullName>
<description>Telecom team use only</description>
<isActive>true</isActive>
<values>
<fullName>New</fullName>
<default>true</default>
</values>
<values>
<fullName>Open</fullName>
<default>false</default>
</values>
</businessProcesses>
sed xml xmlstarlet
Extract the desired content from the file using "xmlstarlet" or "sed" or "awk" or some similar tool.
The process should refer the full name of the particular businessprocesses and then should just extract content in between that particular business process.
File from where the content to be extracted.
<businessProcesses>
<fullName>Customer Support</fullName>
<description>Use for Customer Support, TDG and Port</description>
<isActive>true</isActive>
<values>
<fullName>Action Item</fullName>
<default>false</default>
</values>
<values>
<fullName>Solved</fullName>
<default>false</default>
</values>
</businessProcesses>
<businessProcesses>
<fullName>Customer Support - Port</fullName>
<description>Telecom team use only</description>
<isActive>true</isActive>
<values>
<fullName>New</fullName>
<default>true</default>
</values>
<values>
<fullName>Open</fullName>
<default>false</default>
</values>
</businessProcesses>
</CustomObject>
Required output.
<businessProcesses>
<fullName>Customer Support - Port</fullName>
<description>Telecom team use only</description>
<isActive>true</isActive>
<values>
<fullName>New</fullName>
<default>true</default>
</values>
<values>
<fullName>Open</fullName>
<default>false</default>
</values>
</businessProcesses>
sed xml xmlstarlet
sed xml xmlstarlet
edited Jan 24 at 19:08
glenn jackman
51.5k572111
51.5k572111
asked Jan 24 at 18:37
manoj kmanoj k
1
1
1
When you post your homework, you should at least provide enough information to solve the problem and look at basic formatting rules.
– Ljm Dullaart
Jan 24 at 18:46
2
What research have you made to solve this yourself?
– glenn jackman
Jan 24 at 19:09
add a comment |
1
When you post your homework, you should at least provide enough information to solve the problem and look at basic formatting rules.
– Ljm Dullaart
Jan 24 at 18:46
2
What research have you made to solve this yourself?
– glenn jackman
Jan 24 at 19:09
1
1
When you post your homework, you should at least provide enough information to solve the problem and look at basic formatting rules.
– Ljm Dullaart
Jan 24 at 18:46
When you post your homework, you should at least provide enough information to solve the problem and look at basic formatting rules.
– Ljm Dullaart
Jan 24 at 18:46
2
2
What research have you made to solve this yourself?
– glenn jackman
Jan 24 at 19:09
What research have you made to solve this yourself?
– glenn jackman
Jan 24 at 19:09
add a comment |
2 Answers
2
active
oldest
votes
Assuming that the XML is well formed (the example lacks a CustomObject opening tag),
$ xmlstarlet sel -t -c '//businessProcesses[fullName="Customer Support - Port"]' -nl file.xml
<businessProcesses>
<fullName>Customer Support - Port</fullName>
<description>Telecom team use only</description>
<isActive>true</isActive>
<values>
<fullName>New</fullName>
<default>true</default>
</values>
<values>
<fullName>Open</fullName>
<default>false</default>
</values>
</businessProcesses>
This uses XMLStarlet with an XPATH query that extracts a copy of the businessProcesses node that has a fullName child node with the exact value Customer Support - Port.
The -nl at the end adds a newline to the output.
Don't compare XMLStarlet or any other parser of structured document formats with line-oriented text manipulation tools like sed, or awk.
**It is throwing the following error when I tried the above command! **file.xml:1.1: Start tag expected, '<' not found <businessProcesses>
– manoj k
Jan 24 at 19:46
@manojk Your XML document is malformed. I was assuming that you showed us the actual document. If it has other data in it that is not XML, then this has to be removed first.
– Kusalananda
Jan 24 at 19:50
add a comment |
You can get the desired output (with an extra space) with
awk 'NR==1 || (NR >= 15 && NR <= 26)'
or
sed -n '1p; 15,26p'
If you want a better answer, ask a better question.
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
);
);
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%2f496520%2fextract-content-between-tags-which-is-having-sub-tag%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Assuming that the XML is well formed (the example lacks a CustomObject opening tag),
$ xmlstarlet sel -t -c '//businessProcesses[fullName="Customer Support - Port"]' -nl file.xml
<businessProcesses>
<fullName>Customer Support - Port</fullName>
<description>Telecom team use only</description>
<isActive>true</isActive>
<values>
<fullName>New</fullName>
<default>true</default>
</values>
<values>
<fullName>Open</fullName>
<default>false</default>
</values>
</businessProcesses>
This uses XMLStarlet with an XPATH query that extracts a copy of the businessProcesses node that has a fullName child node with the exact value Customer Support - Port.
The -nl at the end adds a newline to the output.
Don't compare XMLStarlet or any other parser of structured document formats with line-oriented text manipulation tools like sed, or awk.
**It is throwing the following error when I tried the above command! **file.xml:1.1: Start tag expected, '<' not found <businessProcesses>
– manoj k
Jan 24 at 19:46
@manojk Your XML document is malformed. I was assuming that you showed us the actual document. If it has other data in it that is not XML, then this has to be removed first.
– Kusalananda
Jan 24 at 19:50
add a comment |
Assuming that the XML is well formed (the example lacks a CustomObject opening tag),
$ xmlstarlet sel -t -c '//businessProcesses[fullName="Customer Support - Port"]' -nl file.xml
<businessProcesses>
<fullName>Customer Support - Port</fullName>
<description>Telecom team use only</description>
<isActive>true</isActive>
<values>
<fullName>New</fullName>
<default>true</default>
</values>
<values>
<fullName>Open</fullName>
<default>false</default>
</values>
</businessProcesses>
This uses XMLStarlet with an XPATH query that extracts a copy of the businessProcesses node that has a fullName child node with the exact value Customer Support - Port.
The -nl at the end adds a newline to the output.
Don't compare XMLStarlet or any other parser of structured document formats with line-oriented text manipulation tools like sed, or awk.
**It is throwing the following error when I tried the above command! **file.xml:1.1: Start tag expected, '<' not found <businessProcesses>
– manoj k
Jan 24 at 19:46
@manojk Your XML document is malformed. I was assuming that you showed us the actual document. If it has other data in it that is not XML, then this has to be removed first.
– Kusalananda
Jan 24 at 19:50
add a comment |
Assuming that the XML is well formed (the example lacks a CustomObject opening tag),
$ xmlstarlet sel -t -c '//businessProcesses[fullName="Customer Support - Port"]' -nl file.xml
<businessProcesses>
<fullName>Customer Support - Port</fullName>
<description>Telecom team use only</description>
<isActive>true</isActive>
<values>
<fullName>New</fullName>
<default>true</default>
</values>
<values>
<fullName>Open</fullName>
<default>false</default>
</values>
</businessProcesses>
This uses XMLStarlet with an XPATH query that extracts a copy of the businessProcesses node that has a fullName child node with the exact value Customer Support - Port.
The -nl at the end adds a newline to the output.
Don't compare XMLStarlet or any other parser of structured document formats with line-oriented text manipulation tools like sed, or awk.
Assuming that the XML is well formed (the example lacks a CustomObject opening tag),
$ xmlstarlet sel -t -c '//businessProcesses[fullName="Customer Support - Port"]' -nl file.xml
<businessProcesses>
<fullName>Customer Support - Port</fullName>
<description>Telecom team use only</description>
<isActive>true</isActive>
<values>
<fullName>New</fullName>
<default>true</default>
</values>
<values>
<fullName>Open</fullName>
<default>false</default>
</values>
</businessProcesses>
This uses XMLStarlet with an XPATH query that extracts a copy of the businessProcesses node that has a fullName child node with the exact value Customer Support - Port.
The -nl at the end adds a newline to the output.
Don't compare XMLStarlet or any other parser of structured document formats with line-oriented text manipulation tools like sed, or awk.
answered Jan 24 at 19:13
KusalanandaKusalananda
129k16245404
129k16245404
**It is throwing the following error when I tried the above command! **file.xml:1.1: Start tag expected, '<' not found <businessProcesses>
– manoj k
Jan 24 at 19:46
@manojk Your XML document is malformed. I was assuming that you showed us the actual document. If it has other data in it that is not XML, then this has to be removed first.
– Kusalananda
Jan 24 at 19:50
add a comment |
**It is throwing the following error when I tried the above command! **file.xml:1.1: Start tag expected, '<' not found <businessProcesses>
– manoj k
Jan 24 at 19:46
@manojk Your XML document is malformed. I was assuming that you showed us the actual document. If it has other data in it that is not XML, then this has to be removed first.
– Kusalananda
Jan 24 at 19:50
**It is throwing the following error when I tried the above command! **
file.xml:1.1: Start tag expected, '<' not found <businessProcesses>– manoj k
Jan 24 at 19:46
**It is throwing the following error when I tried the above command! **
file.xml:1.1: Start tag expected, '<' not found <businessProcesses>– manoj k
Jan 24 at 19:46
@manojk Your XML document is malformed. I was assuming that you showed us the actual document. If it has other data in it that is not XML, then this has to be removed first.
– Kusalananda
Jan 24 at 19:50
@manojk Your XML document is malformed. I was assuming that you showed us the actual document. If it has other data in it that is not XML, then this has to be removed first.
– Kusalananda
Jan 24 at 19:50
add a comment |
You can get the desired output (with an extra space) with
awk 'NR==1 || (NR >= 15 && NR <= 26)'
or
sed -n '1p; 15,26p'
If you want a better answer, ask a better question.
add a comment |
You can get the desired output (with an extra space) with
awk 'NR==1 || (NR >= 15 && NR <= 26)'
or
sed -n '1p; 15,26p'
If you want a better answer, ask a better question.
add a comment |
You can get the desired output (with an extra space) with
awk 'NR==1 || (NR >= 15 && NR <= 26)'
or
sed -n '1p; 15,26p'
If you want a better answer, ask a better question.
You can get the desired output (with an extra space) with
awk 'NR==1 || (NR >= 15 && NR <= 26)'
or
sed -n '1p; 15,26p'
If you want a better answer, ask a better question.
answered Jan 24 at 19:53
G-ManG-Man
13.1k93465
13.1k93465
add a comment |
add a comment |
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%2f496520%2fextract-content-between-tags-which-is-having-sub-tag%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
1
When you post your homework, you should at least provide enough information to solve the problem and look at basic formatting rules.
– Ljm Dullaart
Jan 24 at 18:46
2
What research have you made to solve this yourself?
– glenn jackman
Jan 24 at 19:09