1、xml文件
<server>
<imservers>
<imserver>
<ip>172.16.100.136</ip>
<port>8100</port>
</imserver>
<imserver>
<ip>localhost</ip>
<port>8001</port>
</imserver>
</imservers>
</server>
2、读取ip地址
# awk '/<ip>/,/<\/ip>/ {print $0}' server.xml | awk -v FS="<ip>" -v OFS=" " '{print $2}' | awk -v FS="<\/ip>" -v OFS=" " '{print $1}'
结果:
172.16.100.136
localhost