Pregunta

I am using a runmqsc command to get the output as following. But i want some of the out removed. I am using egrep and cut but not getting the required result.

Runmqsc command : echo "dis clusqmgr(*) suspend"|runmqsc QMGR1

Original Output:

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)

Desired output:

CLUSQMGR(GWD1) SUSPEND(NO)
CLUSQMGR(GWD2) SUSPEND(NO)

Command i am using to achieve this:

echo "dis clusqmgr(*) suspend"|runmqsc QMGR1|egrep 'CLUSQMGR|SUSPEND'| tr ')' '\n' | grep "CLUSQMGR(" | cut -f 2  -d ")"

Please help.

¿Fue útil?

Solución

One way to pipe your output to:

egrep 'CLUSQMGR|SUSPEND' | paste - - | awk '{print $1, $4}'

For example,

egrep 'CLUSQMGR|SUSPEND' filename | paste - - | awk '{print $1, $4}'

where filename contains the original input posted by you would produce:

CLUSQMGR(GWD1) SUSPEND(NO)
CLUSQMGR(GWD2) SUSPEND(NO)

An alternative would be to pipe the command output to:

egrep -o '\b(CLUSQMGR|SUSPEND)\S+' | paste - -

Otros consejos

What are the boundary parameters? I'm assuming any line with a colon should be ignored, and the first entry from any CLUSQMGR line and the last entry from any SUSPEND line should be merged and printed. The following will only work properly if they both appear, and always in this order:

runmqsc QMGR1 <<<'dis clusqmgr(*) suspend' |
awk '/:/ { g=""; next }
    /CLUSQMGR/ { g=$1; next }
    /SUSPEND/ { print g, $NF; g="" }'

This is obviously ad-hoc; a proper solution would involve a real parser of runmqsc output (googling reveals several attempts, but I cannot judge their quality) or a version of runmqsc which prints properly machine-readble output (e.g. JSON).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top