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







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!










share|improve this question









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




















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!










share|improve this question









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
















0












0








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!










share|improve this question









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






share|improve this question









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.










share|improve this question









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.








share|improve this question




share|improve this question








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





















  • 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



















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












1 Answer
1






active

oldest

votes


















1














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 &amp;), you can unescape these by piping the output of the above command through xmlstarlet unesc.






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


    }
    });






    user365840 is a new contributor. Be nice, and check out our Code of Conduct.










    draft saved

    draft discarded


















    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









    1














    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 &amp;), you can unescape these by piping the output of the above command through xmlstarlet unesc.






    share|improve this answer
































      1














      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 &amp;), you can unescape these by piping the output of the above command through xmlstarlet unesc.






      share|improve this answer






























        1












        1








        1







        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 &amp;), you can unescape these by piping the output of the above command through xmlstarlet unesc.






        share|improve this answer















        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 &amp;), you can unescape these by piping the output of the above command through xmlstarlet unesc.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 1 hour ago

























        answered 1 hour ago









        KusalanandaKusalananda

        158k18 gold badges313 silver badges498 bronze badges




        158k18 gold badges313 silver badges498 bronze badges

























            user365840 is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            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.




            draft saved


            draft discarded














            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





















































            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

            Hudson River Historic District Contents Geography History The district today Aesthetics Cultural...

            The number designs the writing. Feandra Aversely Definition: The act of ingrafting a sprig or shoot of one...

            Ayherre Geografie Demografie Externe links Navigatiemenu43° 23′ NB, 1° 15′ WL43° 23′ NB, 1°...