Extract content between tags which is having sub tag

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












-4















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> 









share|improve this question



















  • 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















-4















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> 









share|improve this question



















  • 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













-4












-4








-4








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> 









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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












  • 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










2 Answers
2






active

oldest

votes


















0














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.






share|improve this answer























  • **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



















0














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.






share|improve this answer






















    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
    );



    );













    draft saved

    draft discarded


















    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









    0














    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.






    share|improve this answer























    • **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
















    0














    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.






    share|improve this answer























    • **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














    0












    0








    0







    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.






    share|improve this answer













    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.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    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


















    • **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














    0














    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.






    share|improve this answer



























      0














      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.






      share|improve this answer

























        0












        0








        0







        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 24 at 19:53









        G-ManG-Man

        13.1k93465




        13.1k93465



























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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

            Peggy Mitchell

            Palaiologos

            The Forum (Inglewood, California)