I'm trying to understand AWK command. The problem that I'm trying to solve is as follow: I have XML file with structure:
<root>
...
<elem_name name='type1'>
...
<prop name='a' type="xxx" value="000"/>
<prop name='b' type="xxx" value="000"/>
<prop name='c' type="xxx" value="000"/>
...
</elem_name>
<elem_name name='type2'>
....
<prop name='a' type="xxx" value="000"/>
<prop name='b' type="xxx" value="000"/>
<prop name='c' type="xxx" value="000"/>
...
</elem_name>
...
</root>
And I have to edit value of prop 'b' under 'type1' root. As I mentioned I would like to do it with awk or sed. I'm aware of better tools to do it.
For now, I created following command, but it is not working properly.
gawk '/elem_name name="type1"/ {for(i=1; i<=4; i++) {getline;found=index($0,"a");if(found != 0){sub("value=", "test", $0)}; print > "test.xml"}} {print > "test.xml" }' original_file.xml
Firstly, I the value is not changed after script execution, the 'name="type1" is removed from output file.