I'm trying with the code below to replace the values between "<>" to right, but is not working I'm not sure why.
Myfile=Menu.xml
awk -F "[<>]" '{print $2}' ${Myfile} | while read data
do
cat <<-TEXT1
if ["${data}" -eq "food"]; then
sed "s/${data}/Catg/" ${Myfile}
else
sed "s/${data}/Unit><Data :Value="String"/" ${Myfile}
fi
TEXT1
done
sed dosn't change file in place unless you use the -i option
it's never a good idea to read and write to the same file at one (ie sed changes file awk is still reading)
The double quotes in your 2nd sed command need to be quoted to protect from the shell. Good general rule of thumb is to use single quotes for sed/awk code
Var="Today Breakfast"
sed "/<Catg>/a\<Unit><Data :Value=\"String\">${Var}</Data></Unit>" input_file
--ahamed
---------- Post updated at 09:14 PM ---------- Previous update was at 09:12 PM ----------
sed '...' input_file | sed "..."
--ahamed
---------- Post updated at 09:16 PM ---------- Previous update was at 09:14 PM ----------
sed '/^<.*>[ ]*$/{d};s/food/Catg/g;s/<[^<].*>\(.*\)<\/.*>/<Unit><Data :Value="String">\1<\/Data><\/Unit>/g ' input_file
| sed "/<Catg>/a\<Unit><Data :Value=\"String\">${Var}</Data></Unit>"
Thanks ahmed works great, only I'm figure it out how to print only the "<food>" blocks removing the others lines that could be
present ("<? xml...", "<breakfast_menu", "</breakfast_menu" etc).
Hi Chubler_XL for both options, both work great, but if the xml file contains more lines between <food's> blocks the code will not
consider them and if the lines between <food> and </food> are different to "name", "price" and "calories" etc, will not be consider either.
It could be more lines than those 3, and could be different from file to file than in the sample.