- 论坛徽章:
- 0
|
本帖最后由 wdong_2001 于 2012-02-22 14:18 编辑
HI
有两个文件(同一个文件名,内容为两种方式)
ls app.properties (,号方式)
jetty,192.168.126.247,test,/opt/jetty-6.1.22-AA/webapps/,testAA.war
jetty,192.168.126.247,test,/opt/jetty-6.1.22-AA/webapps/,testAA.war
ls app.properties (空格方式)
jetty:192.168.126.247 test /opt/jetty-6.1.22-AA/webapps/ testAA.war
jetty:192.168.126.247 test /opt/jetty-6.1.22-AA/webapps/ testAA.war
现在用脚本跑
for lineStr in $(cat ${scriptDir}/app.properties |grep -v "#"|grep -w "${getPackageName}"
do
#list=($(echo $lineStr | awk -F'[:\t]' '{print $1}' |grep -v "#"|sort |uniq)) (空格方式)
list=($(echo $lineStr | awk -F',' '{printf("%s %s %s %s %s",$1,$2,$3,$4,$5)}' |grep -v "#") (,号方式)
echo "1==={list[0]}==2==={list[1]}==3==={list[2]}==4==={list[3]}==5==={list[4]}"
sleep 5
echo containerTypecontainerType
if [ -z $containerType ];then
containerType=${list[0]}
echo containerType1111containerType
elif [ $containerType != ${list[0]} ];then
echo "containerType is wrongcontainerType and ${list[0]} is not the same container......"
exit;
fi
done
我是想得出到jetty 关键字(${list[0]})
问:为什么用“,”号的;显示:
getPackageName1111 : testAA.war
1===:jetty==2===:192.168.126.210==3===:test==4===:/opt/jetty-6.1.22-AA/webapps/==5===:testAA.war
containerType1111:jetty
1===:jetty==2===:192.168.126.247==3===:test==4===:/opt/jetty-6.1.22-BB/webapps/==5===:testAA.war
而用空格的;显示:
getPackageName1111 : testAA.war
1===:jetty:192.168.126.210==2===:==3===:==4===:==5===:
containerType1111:jetty:192.168.126.210
1===:test==2===:==3===:==4===:==5===:
containerType:jetty:192.168.126.210
containerType is wrong:jetty:192.168.126.210 and test is not the same container......
为什么,用“,”是按每行开头来,而用“空格”只是当成一行来的???
我现在想app.properties内容为以“空格”方式。而得的结果像“,”方式,请问awk 如何写????
|
|