Guys, first post be kind!
Need some guidance here
I plan to edit 3 xml files without opening them (as opening, editing, closing is more prone to errors).
The one I want to edit is with a condition.
I need to update N to Y wherever I see Flag_XYZ_TurnOn in all 3 files. Also I prefer to run it from command line rather than having it in a script.
Example of the pattern:
Before:
<Name>Flag_XYZ_TurnOn</Name>
<Value>N</Value>
After:
<Name>Flag_XYZ_TurnOn</Name>
<Value>Y</Value>
I wrote SED commands and it works great in Linux but NOT in Unix
I tried the following sed commands from command line
sed -i.saved '/Flag_xyz_/{n;s/N/Y/}' infile_1 infile_2
sed '/Flag_xyz_/{n;s/N/Y/}' input_file
So as an alternative to sed I tried looking at awk as it is compatible with Unix too. But instead of command line it is making to write a script example below, which am personally not prefering.
for i in `find . -type f -name "*.xml"`
do
awk '/Flag_xyz_TurnOn/{n=NR+1}NR==n{sub(/>N</,">Y<")}1' $i > /temp/tmp123.xml
cp /temp/tmp123.xml $i
rm /temp/tmp123.xml
done
Anybody can suggest me to write in a better way? So that its a single line command, which i can run from command line to achieve my desired result?
Thanking you in advance.
cheers