I need to find a value in file between >STRING<

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











up vote
0
down vote

favorite
1












I have a file: example here:



 <hello>TestFile</hello>
<test>2018-04-30</test>
<greetings>mycomputer</greetings>
**<Iwanthis>6.1.0</Iwanthis>**
<example>20180411</example>
blah blah


I'm looking to grep the value (in this case 6.1.0) from between
6.1.0



is there an way to grep the file to grab the XXXX value?



regards



thanks all........







share|improve this question

















  • 2




    Is this an XML file?
    – Stephen Kitt
    May 2 at 12:25










  • Sorry - this a standard file - Not XML
    – Mike Smith
    May 2 at 12:26










  • I should mention - I need a solution in Bash - sorry for not mentioning it!
    – Mike Smith
    May 2 at 12:27










  • Bash is just a shell, not much of a text editor. You’re looking for a command-line solution? Grep, awk, sed, that sort of thing?
    – Jeff Schaller
    May 2 at 12:28










  • Yup - any of that would suffice once I can assign the XXXX into a variable to manipulate :P It's the special characters that are confusing me.
    – Mike Smith
    May 2 at 12:48














up vote
0
down vote

favorite
1












I have a file: example here:



 <hello>TestFile</hello>
<test>2018-04-30</test>
<greetings>mycomputer</greetings>
**<Iwanthis>6.1.0</Iwanthis>**
<example>20180411</example>
blah blah


I'm looking to grep the value (in this case 6.1.0) from between
6.1.0



is there an way to grep the file to grab the XXXX value?



regards



thanks all........







share|improve this question

















  • 2




    Is this an XML file?
    – Stephen Kitt
    May 2 at 12:25










  • Sorry - this a standard file - Not XML
    – Mike Smith
    May 2 at 12:26










  • I should mention - I need a solution in Bash - sorry for not mentioning it!
    – Mike Smith
    May 2 at 12:27










  • Bash is just a shell, not much of a text editor. You’re looking for a command-line solution? Grep, awk, sed, that sort of thing?
    – Jeff Schaller
    May 2 at 12:28










  • Yup - any of that would suffice once I can assign the XXXX into a variable to manipulate :P It's the special characters that are confusing me.
    – Mike Smith
    May 2 at 12:48












up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





I have a file: example here:



 <hello>TestFile</hello>
<test>2018-04-30</test>
<greetings>mycomputer</greetings>
**<Iwanthis>6.1.0</Iwanthis>**
<example>20180411</example>
blah blah


I'm looking to grep the value (in this case 6.1.0) from between
6.1.0



is there an way to grep the file to grab the XXXX value?



regards



thanks all........







share|improve this question













I have a file: example here:



 <hello>TestFile</hello>
<test>2018-04-30</test>
<greetings>mycomputer</greetings>
**<Iwanthis>6.1.0</Iwanthis>**
<example>20180411</example>
blah blah


I'm looking to grep the value (in this case 6.1.0) from between
6.1.0



is there an way to grep the file to grab the XXXX value?



regards



thanks all........









share|improve this question












share|improve this question




share|improve this question








edited May 2 at 12:27
























asked May 2 at 12:24









Mike Smith

11




11







  • 2




    Is this an XML file?
    – Stephen Kitt
    May 2 at 12:25










  • Sorry - this a standard file - Not XML
    – Mike Smith
    May 2 at 12:26










  • I should mention - I need a solution in Bash - sorry for not mentioning it!
    – Mike Smith
    May 2 at 12:27










  • Bash is just a shell, not much of a text editor. You’re looking for a command-line solution? Grep, awk, sed, that sort of thing?
    – Jeff Schaller
    May 2 at 12:28










  • Yup - any of that would suffice once I can assign the XXXX into a variable to manipulate :P It's the special characters that are confusing me.
    – Mike Smith
    May 2 at 12:48












  • 2




    Is this an XML file?
    – Stephen Kitt
    May 2 at 12:25










  • Sorry - this a standard file - Not XML
    – Mike Smith
    May 2 at 12:26










  • I should mention - I need a solution in Bash - sorry for not mentioning it!
    – Mike Smith
    May 2 at 12:27










  • Bash is just a shell, not much of a text editor. You’re looking for a command-line solution? Grep, awk, sed, that sort of thing?
    – Jeff Schaller
    May 2 at 12:28










  • Yup - any of that would suffice once I can assign the XXXX into a variable to manipulate :P It's the special characters that are confusing me.
    – Mike Smith
    May 2 at 12:48







2




2




Is this an XML file?
– Stephen Kitt
May 2 at 12:25




Is this an XML file?
– Stephen Kitt
May 2 at 12:25












Sorry - this a standard file - Not XML
– Mike Smith
May 2 at 12:26




Sorry - this a standard file - Not XML
– Mike Smith
May 2 at 12:26












I should mention - I need a solution in Bash - sorry for not mentioning it!
– Mike Smith
May 2 at 12:27




I should mention - I need a solution in Bash - sorry for not mentioning it!
– Mike Smith
May 2 at 12:27












Bash is just a shell, not much of a text editor. You’re looking for a command-line solution? Grep, awk, sed, that sort of thing?
– Jeff Schaller
May 2 at 12:28




Bash is just a shell, not much of a text editor. You’re looking for a command-line solution? Grep, awk, sed, that sort of thing?
– Jeff Schaller
May 2 at 12:28












Yup - any of that would suffice once I can assign the XXXX into a variable to manipulate :P It's the special characters that are confusing me.
– Mike Smith
May 2 at 12:48




Yup - any of that would suffice once I can assign the XXXX into a variable to manipulate :P It's the special characters that are confusing me.
– Mike Smith
May 2 at 12:48










2 Answers
2






active

oldest

votes

















up vote
2
down vote













If you can trust that there will be one opening tag and one closing tag on that line, you can use this as field separator for awk:



awk -F "</*Iwanthis>" '(NF > 1)print $2' yourfile


This will fail on a lot of artificial cases. To be more strict, you could use sed:



sed -n 's_.*<Iwanthis>(.*)</Iwanthis>.*_1_p' yourfile


The -n suppresses default output, so you just get output on the matching line. I did chose the underscore as delimiter for the s command to avoid escaping the slash. The s command will replace the whole line by the part between the opening and closing tag (the 1 refers to the (.*) part)
Of course you can still create weird cases to make this fail.






share|improve this answer























  • I feel bad now - I tried for hours last night and did it 100% in just a few minutes...
    – Mike Smith
    May 2 at 13:25










  • I salute you SIR!!! Perfect - Does exactly what I wanted!!
    – Mike Smith
    May 2 at 13:25

















up vote
2
down vote













Sure looks like an XML file. Add a root note and use an XML parser:



$ echo '<r>'; cat file; echo '</r>'; | xmlstarlet sel -t -v //Iwanthis
6.1.0





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',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    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%2f441310%2fi-need-to-find-a-value-in-file-between-string%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote













    If you can trust that there will be one opening tag and one closing tag on that line, you can use this as field separator for awk:



    awk -F "</*Iwanthis>" '(NF > 1)print $2' yourfile


    This will fail on a lot of artificial cases. To be more strict, you could use sed:



    sed -n 's_.*<Iwanthis>(.*)</Iwanthis>.*_1_p' yourfile


    The -n suppresses default output, so you just get output on the matching line. I did chose the underscore as delimiter for the s command to avoid escaping the slash. The s command will replace the whole line by the part between the opening and closing tag (the 1 refers to the (.*) part)
    Of course you can still create weird cases to make this fail.






    share|improve this answer























    • I feel bad now - I tried for hours last night and did it 100% in just a few minutes...
      – Mike Smith
      May 2 at 13:25










    • I salute you SIR!!! Perfect - Does exactly what I wanted!!
      – Mike Smith
      May 2 at 13:25














    up vote
    2
    down vote













    If you can trust that there will be one opening tag and one closing tag on that line, you can use this as field separator for awk:



    awk -F "</*Iwanthis>" '(NF > 1)print $2' yourfile


    This will fail on a lot of artificial cases. To be more strict, you could use sed:



    sed -n 's_.*<Iwanthis>(.*)</Iwanthis>.*_1_p' yourfile


    The -n suppresses default output, so you just get output on the matching line. I did chose the underscore as delimiter for the s command to avoid escaping the slash. The s command will replace the whole line by the part between the opening and closing tag (the 1 refers to the (.*) part)
    Of course you can still create weird cases to make this fail.






    share|improve this answer























    • I feel bad now - I tried for hours last night and did it 100% in just a few minutes...
      – Mike Smith
      May 2 at 13:25










    • I salute you SIR!!! Perfect - Does exactly what I wanted!!
      – Mike Smith
      May 2 at 13:25












    up vote
    2
    down vote










    up vote
    2
    down vote









    If you can trust that there will be one opening tag and one closing tag on that line, you can use this as field separator for awk:



    awk -F "</*Iwanthis>" '(NF > 1)print $2' yourfile


    This will fail on a lot of artificial cases. To be more strict, you could use sed:



    sed -n 's_.*<Iwanthis>(.*)</Iwanthis>.*_1_p' yourfile


    The -n suppresses default output, so you just get output on the matching line. I did chose the underscore as delimiter for the s command to avoid escaping the slash. The s command will replace the whole line by the part between the opening and closing tag (the 1 refers to the (.*) part)
    Of course you can still create weird cases to make this fail.






    share|improve this answer















    If you can trust that there will be one opening tag and one closing tag on that line, you can use this as field separator for awk:



    awk -F "</*Iwanthis>" '(NF > 1)print $2' yourfile


    This will fail on a lot of artificial cases. To be more strict, you could use sed:



    sed -n 's_.*<Iwanthis>(.*)</Iwanthis>.*_1_p' yourfile


    The -n suppresses default output, so you just get output on the matching line. I did chose the underscore as delimiter for the s command to avoid escaping the slash. The s command will replace the whole line by the part between the opening and closing tag (the 1 refers to the (.*) part)
    Of course you can still create weird cases to make this fail.







    share|improve this answer















    share|improve this answer



    share|improve this answer








    edited May 2 at 12:56


























    answered May 2 at 12:51









    Philippos

    5,89211544




    5,89211544











    • I feel bad now - I tried for hours last night and did it 100% in just a few minutes...
      – Mike Smith
      May 2 at 13:25










    • I salute you SIR!!! Perfect - Does exactly what I wanted!!
      – Mike Smith
      May 2 at 13:25
















    • I feel bad now - I tried for hours last night and did it 100% in just a few minutes...
      – Mike Smith
      May 2 at 13:25










    • I salute you SIR!!! Perfect - Does exactly what I wanted!!
      – Mike Smith
      May 2 at 13:25















    I feel bad now - I tried for hours last night and did it 100% in just a few minutes...
    – Mike Smith
    May 2 at 13:25




    I feel bad now - I tried for hours last night and did it 100% in just a few minutes...
    – Mike Smith
    May 2 at 13:25












    I salute you SIR!!! Perfect - Does exactly what I wanted!!
    – Mike Smith
    May 2 at 13:25




    I salute you SIR!!! Perfect - Does exactly what I wanted!!
    – Mike Smith
    May 2 at 13:25












    up vote
    2
    down vote













    Sure looks like an XML file. Add a root note and use an XML parser:



    $ echo '<r>'; cat file; echo '</r>'; | xmlstarlet sel -t -v //Iwanthis
    6.1.0





    share|improve this answer

























      up vote
      2
      down vote













      Sure looks like an XML file. Add a root note and use an XML parser:



      $ echo '<r>'; cat file; echo '</r>'; | xmlstarlet sel -t -v //Iwanthis
      6.1.0





      share|improve this answer























        up vote
        2
        down vote










        up vote
        2
        down vote









        Sure looks like an XML file. Add a root note and use an XML parser:



        $ echo '<r>'; cat file; echo '</r>'; | xmlstarlet sel -t -v //Iwanthis
        6.1.0





        share|improve this answer













        Sure looks like an XML file. Add a root note and use an XML parser:



        $ echo '<r>'; cat file; echo '</r>'; | xmlstarlet sel -t -v //Iwanthis
        6.1.0






        share|improve this answer













        share|improve this answer



        share|improve this answer











        answered May 2 at 13:41









        glenn jackman

        45.8k265100




        45.8k265100






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f441310%2fi-need-to-find-a-value-in-file-between-string%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay