@(description=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=211.67.48.11)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=211.67.48.12)(PORT=1521)))(FAILOVER=yes)(LOAD_BALANCE=yes)(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = YWKDB)))"
上面是oracle connect str,我想使用grep或sed或awk获取所有IP和PORT信息,例如211.67.48.11:1521,211.67.48.12:1521
和sidname:YWKDB
str在TOMCAT_HOME / conf / context.xml中,我需要获取IP信息。
答案 0 :(得分:1)
代码注释。
# The input. Sorry cat.
cat <<'EOF' |
@(description=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=211.67.48.11)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=211.67.48.12)(PORT=1521)))(FAILOVER=yes)(LOAD_BALANCE=yes)(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = YWKDB)))
EOF
{
# substitute `(` for newlines
tr '(' '\n' |
# substitue `)` for newlines
tr ')' '\n' |
# now that we have all in newlines, we can filter HOST and PORT lines
grep 'HOST\|PORT' |
# remove the HOST and PORT part before `=`
sed 's/[^=]*=//' |
# read two lines at a time
while read host && read port; do
# some output
echo "HOST=$host PORT=$port"
done
}
将输出:
HOST=211.67.48.11 PORT=1521
HOST=211.67.48.12 PORT=1521