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>

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

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. Mar 18, 2019 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.