0

My XML file;

<settings version="2">
    <setting id="TimeShift" default="true">0</setting>
    <setting id="Override" default="true">false</setting>
    <setting id="Cache">true</setting>
    <setting id="Path">/storage/</setting>
    <setting id="PathType">0</setting>
    <setting id="Url1">http://localhost:8080/main.php?value1=abcd-1234&value2=OqUy1cHm&type=post</setting>
    <setting id="startNum">1</setting>
</settings>

I need to extract the variable URL value. I tried some sed and grep commands but don't get result. Which command should I use?

1

Assuming that the URL is actually encoded properly (it isn't now, which would break some XML parsers; both & should be &amp;):

$ xmlstarlet sel -t -v '/settings/setting[@id = "Url1"]' -nl file.xml
http://localhost:8080/main.php?value1=abcd-1234&amp;value2=OqUy1cHm&amp;type=post

This uses xmlstarlet to fetch the value for the /settings/setting document node whose id attribute is Url1.

  • Thank you for this valuable information. You are right for (&) character. I did a manual copy-paste of the url for the example. – Ali Haydar Doğan Mar 18 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.