我正在运行
echo "dis clusqmgr(*) suspend"|runmqsc QMGR1
获取以下输出,但我想删除其中一些。我尝试过使用egrep
和cut
,但无法获得所需的结果。
原始输出:
1 : dis clusqmgr(*) suspend
AMQ8441: Display Cluster Queue Manager details.
CLUSQMGR(GWD1) CHANNEL(TO.GWD1.SSL)
CLUSTER(CLUSD) SUSPEND(NO)
AMQ8441: Display Cluster Queue Manager details.
CLUSQMGR(GWD2) CHANNEL(TO.GWD2.SSL)
CLUSTER(CLUSD) SUSPEND(NO)
期望的输出:
CLUSQMGR(GWD1) SUSPEND(NO)
CLUSQMGR(GWD2) SUSPEND(NO)
我用来实现这个目的:
echo "dis clusqmgr(*) suspend"|runmqsc QMGR1|egrep 'CLUSQMGR|SUSPEND'| tr ')' '\n' | grep "CLUSQMGR(" | cut -f 2 -d ")"
答案 0 :(得分:2)
$ cat t.txt
1 : dis clusqmgr(*) suspend
AMQ8441: Display Cluster Queue Manager details.
CLUSQMGR(GWD1) CHANNEL(TO.GWD1.SSL)
CLUSTER(CLUSD) SUSPEND(NO)
AMQ8441: Display Cluster Queue Manager details.
CLUSQMGR(GWD2) CHANNEL(TO.GWD2.SSL)
CLUSTER(CLUSD) SUSPEND(NO)
$ awk '/^CLUSQMGR/{clusqmgr=$1;t=1}t&&/^CLUSTER/{t=0;print clusqmgr, $2}' t.txt
CLUSQMGR(GWD1) SUSPEND(NO)
CLUSQMGR(GWD2) SUSPEND(NO)
所以
$ echo "dis clusqmgr(*) suspend" | runmqsc QMGR1 | awk '/^CLUSQMGR/{clusqmgr=$1;t=1}t&&/^CLUSTER/{t=0;print clusqmgr, $2}'
应该会产生你想要的结果。
答案 1 :(得分:0)
echo "dis clusqmgr(*) suspend"|runmqsc QMGR1|egrep 'CLUSQMGR|SUSPEND'|paste - - | awk '{print $1,$4}'
给我提供所需的输出
CLUSQMGR(GWD1)暂停(否) CLUSQMGR(GWD2)暂停(否)