Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to extract a specific text of an already extracted XML text in bash script
    primarykey
    data
    text
    <p>I managed to extract a value from a XML file:</p> <pre><code>&lt;--more labels up this line&gt; &lt;ExtraDataItem name="GUI/LastVMSelected" value="14cd3204-4774-46b8-be89-cc834efcba89"/&gt; &lt;--more labels and text down this line--&gt; </code></pre> <p>by using this:</p> <pre><code> UUID=$(sed -ne '/name="GUI\/LastVMSelected"/s/.*value="\([^"]*\)".*/\1/p' inputfile.xml) echo $UUID </code></pre> <p>I have this result in console:</p> <pre><code>14cd3204-4774-46b8-be89-cc834efcba89 </code></pre> <p>That's it! But now, I need to use that UUID to get to another part of the same XML file, that I didn't show before. I simplified the XML file just to show the most relevant labels: </p> <pre><code> &lt;--more labels up this line&gt; &lt;ExtraDataItem name="GUI/LastVMSelected" value="14cd3204-4774-46b8-be89-cc834efcba89"/&gt; &lt;--more labels and text down this line--&gt; &lt;MachineEntry uuid="{14cd3204-4774-46b8-be89-cc834efcba89}" src="Machines/SomeMachine/SomeMachine.xml"/&gt; &lt;--more labels and text down this line--&gt; </code></pre> <p><strong>I need to get "SomeMachine"</strong> without extension, only that name. I tried myself adding some lines:</p> <pre><code>UUID=$(sed -ne '/name="GUI\/LastVMSelected"/s/.*value="\([^"]*\)".*/\1/p' inputfile.xml) LastVMname=$(sed -ne '/MachineEntry uuid="{'$UUID'}"/s/.*src="Machines\([^"]*\).xml".*/\1/p' inputfile.xml) echo $LastVMname </code></pre> <p>But I get this output: </p> <pre><code>/SomeMachine/SomeMachine </code></pre> <p>and I don't how to get rid of /SomeMachine/SomeMachine, just need "SomeMachine". Sed documentation is quite confusing :S</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload