发布网友 发布时间:2022-04-23 06:51
共2个回答
热心网友 时间:2022-06-17 01:28
如果获取到节点话,就调用attributeValue(String name)方法获取里面的值就好了。
$cat test.sh
#!/bin/bash
if [ -z $1 ];then
echo 'USAGE:COMMAND FILENAME'
exit 0
fi
filename=record.txt
HOST=(`sed -n 's/.*>\(.*\)<\/host>/\1/p' $1`)
OIDG=(`sed -n 's/.*>\(.*\)<\/oidgroupname>/\1/p' $1`)
COMM=(`sed -n 's/.*>\(.*\)<\/communitystring>/\1/p' $1`)
DESC=(`sed -n 's/.*>\(.*\)<\/description>/\1/p' $1`)
FILE=(`ls -l $filename >/dev/null 2>&1 | awk '{print $8}'`)
if [ ! -z $FILE ];then
echo -e "host\t\toidgroupname\t\tcomm\t\tdesc" >$filename
fi
for((i=0;i<${#HOST[@]};i++));do
echo -e "${HOST[i]}\t${OIDG[i]}\t${COMM[i]}\t\t${DESC[i]}" >>$filename
done
$./test.sh file
$cat record.txt
host oidgroupname comm desc
192.168.1.1 CpuUtilization_MF public 192.168.1.1_CPUUtilizaton
192.168.1.2 CpuUtilization_MF public 192.168.1.2_CPUUtilizaton
192.168.1.3 CpuUtilization_MF public 192.168.1.3_CPUUtilizaton
192.168.1.4 CpuUtilization_MF public 192.168.1.4_CPUUtilizaton
192.168.1.5 CpuUtilization_MF public 192.168.1.5_CPUUtilizaton
热心网友 时间:2022-06-17 01:29
sed -nr '/<abc>.*<\/abc>/s_.*<abc>([^<]*)</abc>.*_\1_p' 文件名
s_A_B_
将A替换为B
B中 \1 即代表A中第一个小括号里的内容。