Sunday, 1 February 2015

Editing xml using bash and awk, awk don't replace text



I have a config file, with new version code, like a SAD10A_BNA_1234_123456_110011, and this number is write to config.txt, and this number I must place in 4 places on this xml file.


This is my script:




#!/bin/bash

NewNumber=`cat config.txt`

echo $NewNumber
#This number is: PLE31Z_BNE_1111_1121211_313131

awk '/"Parameter1"/ && !done++{sub(/Parameter1="[A-Z0-9]"/, "Parameter1=\"'$NewNumber'\"")}1' OldFileWithVersionNumeber.xml > temp.xml && mv -f temp.xml Newfile$NewNumber.xml

#I know, I must write 3 awk, but first one doesn't work for now

cat targettext.xml | grep Parameter1


XML with old parameter:




<OneSection Parameter1="SAD10A_BNA_1234_123456_110011" Parameter2="SAD10A_BNA_1234_123456_110011" Type="UWE-AD" date="05/01/2011">

AND LOT OF VERY SIMILAR LINES
AND TWO LINES WITH THE SAME NUMBER TO REPLACE

<xmlElement Name="" name="NameGB" version="_SAD10A_BNA_1234_123456_110011.xml" Unit="ERF" Blocks="1" params1="" params2="" Path1="/rom/" path2="" comp="" encrypted="">
<xmlElement KeyName="" name="NameGB" version="_SAD10A_BNA_1234_123456_110011.xml" Unit="ERFS" Blocks="1" params1="" params2="" Path1="/rom/" path2="" comp="" encrypted="">


No comments:

Post a Comment