awk -v casename="keypad_test" -v dis="hhhh" -v tes="hhhh" -f replace.awk output.xml > outputr.xml
replace.awk:
BEGIN {
f=0
g=0
}
$0 ~ casename {
f=1
}
f && /<item[ ]*Displayable/ {
r=" <item Displayable=\"" dis "\" Testable=\"" tes "\" Manual=\"true\">"
g=1
print r
}
/<TestItem/ {
g=f=0
}
/<\/item>/ {
g=f=0
}
!g {
print $0
}
output.xml :
<?xml version="1.0" encoding="utf-8" ?>
<TestItem Port="1" TMode="factory">
<item Displayable="true" Testable="true" Manual="true">
<Title>keypad</Title>
<CaseName>keypad_test</CaseName>
<Description>power,volume+,volume-,menu,home,back/Description>
<ExpectingResult>OK</ExpectingResult>
</item>
<item Displayable="true" Testable="true">
<Title> WIFI</Title>
<CaseName>WIFI</CaseName>
<Atc>
<Action>at$test,wifi,autocheck</Action>
<ExpectingResult>OK</ExpectingResult>
</Atc>
</item>
<item Displayable="true" Testable="true">
<Title>GPS</Title>
<CaseName>gps</CaseName>
<Atc>
<Action>at$test,gps,-c1,-t180</Action>
<ExpectingResult>OK</ExpectingResult>
</Atc>
</item>
<item Displayable="true" Testable="true">
<Title> USB</Title>
<Atc>
<Action>at$dread,usb,isconfiged</Action>
<ExpectingResult>OK</ExpectingResult>
</Atc>
<CaseName>usb_test</CaseName>
</item>
</TestItem>
#su xinmin 2014.2.28
# according to IsActive attribute in dev_cfg.xml to change the Displayable and Testable attribute in augu_factory_test.xml
#check if file exist or not
if [ ! -f dev_cfg.xml ]; then
echo " file dev_cfg.xml is not exist !"
return
fi
if [ ! -f augu_factory_test.xml ]; then
echo " file augu_factory_test.xml is not exist !"
return
fi
if [ ! -f replace.awk ]; then
echo " file replace.awk is not exist !"
return
fi
#reverse output.xml to outputr.xml
sed -e '1!G;h;$!d' augu_factory_test.xml > outputr.xml
#pick out IsActive attribute is YES in dev_cfg.xml
awk '/[ \t]*<DEVICE/{print $2 $6 }' dev_cfg.xml | awk -F/ '{print $1}' | awk -F= '{print $2 $3}' | awk -F\" '{print $2 " " $4}' | awk '$2=="YES" {print $1}' > true.txt
#change the Displayable and Testable attribute in augu_factory_test.xml to true
for tt in `cat true.txt`;do
awk -v casename=$tt -v dis="true" -v tes="true" -f replace.awk outputr.xml > outputr2.xml
mv outputr2.xml outputr.xml
done
#pick out IsActive attribute is NO in dev_cfg.xml
awk '/[ \t]*<DEVICE/{print $2 $6 }' dev_cfg.xml | awk -F/ '{print $1}' | awk -F= '{print $2 $3}' | awk -F\" '{print $2 " " $4}' | awk '$2=="NO" {print $1}' > false.txt
#change the Displayable and Testable attribute in augu_factory_test.xml to false
for tt in `cat false.txt`;do
awk -v casename=$tt -v dis="false" -v tes="false" -f replace.awk outputr.xml > outputr2.xml
mv outputr2.xml outputr.xml
done
sed -e '1!G;h;$!d' outputr.xml > augu_factory_test.xml
rm outputr.xml true.txt false.txt