I've been strugling with the flip-flop operator in order to replace a particular value in a input xml file.
The file structure is as follows:
<a>BLE</a>
<-- hur dur -->
<b>12345</b>
<-- hur der -->
<c>VER1.2.3</c>
<-- hur dest -->
<d>VER1.2.3</d>
<a>CLE</a>
<-- hur dur -->
<b>12345</b>
<-- hur der -->
<c>VERX'.Y'.Z'</c>
<-- hur dest -->
<d>VERX'.Y'.Z'</d>
<a>DLE</a>
<-- hur dur -->
<b>12345</b>
<-- hur der -->
<c>VERX".Y".Z"</c>
<-- hur dest -->
<d>VERX".Y".Z"</d>
etc ...
So lets say I want to change the version field (d and c) of any particular variable. For brevity sake let it be BLE. I have to first find the block with the values of BLE (lines 1-7) and then replace fields and with the new value.
I've been trying different stuff, like:
perl -pi.bak -ne 'if ( /BLE/ .. /<\/d/ ){ s/VER[[:digit:]]\+\.[[:digit:]]\+\.[A-Z][[:digit:]]\+[A-Z]\?/$ver/}' dur.xml
or
perl -ne "print if ( /BLE/ .. /<\/d>/ ) " dur.xml | sed "/VER[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+[A-Z]\?/$ver/"
where $ver is a set variable (ver="VERX.Y.Z"). However the first one doesn't do anything to the input file (I'd prefer to do it in-place); the second produces more or less what I want but the output is limited to the BLE block:
<a>BLE</a>
<-- hur dur -->
<b>12345</b>
<-- hur der -->
<c>VERX.Y.Z</c>
<-- hur dest -->
<d>VERX.Y.Z</d>
but that this output can't be easily redirected to a file with > because it drops everything else besides BLE.
Is there any way one can modify the original file in a similar fashion as the one described above?
Thanks a bunch, drinker
buildversion
string in your example data... – jm666<-- ... -->
? And you only want to change the<d>
where<a>
hasBLE
? – simbabque