This works for me on AIX to get the desired result. This uses the IBM MQ WHERE to limit queued output with CURDEPTH greater than 0:
echo "DIS QL(*) WHERE(CURDEPTH GT 0)" | runmqsc <qmgr> | sed -e 's/\((.*)\) *\(.*\)/\1\ \2/g' -e 's/^ *\([AZ][AZ]*[(][^)][^)]*[)]\)/\1/g' -e 's/^\(AMQ[0-9][0-9]*:\).*$/\1/g' | awk -F '[()]' -v OFS=" " 'function printValues() { if ("QUEUE" in p) { print p["QUEUE"], p["CURDEPTH"] } } /AMQ8409:/ { printValues(); for (i in p) { delete p[i] }; next } { p[$1] = $2 } END { printValues() }'
Note that the above two lines, \ at the end of the first line allows the sed command to replace the inline new line. Syntax awk printValues ββfrom @ mike.dld answer to this post Print part of the array or file and sort in the shell . "I had to replace its delete p with for (i in p) { delete p[i] } , since AIX awk did not support other syntax.
If you want to use the file as an input file, use the following:
cat file | sed -e 's/\((.*)\) *\(.*\)/\1\ \2/g' -e 's/^ *\([AZ][AZ]*[(][^)][^)]*[)]\)/\1/g' -e 's/^\(AMQ[0-9][0-9]*:\).*$/\1/g' | awk -F '[()]' -v OFS=" " 'function printValues() { if ("QUEUE" in p) { print p["QUEUE"], p["CURDEPTH"] } } /AMQ8409:/ { printValues(); for (i in p) { delete p[i] }; next } { p[$1] = $2 } END { printValues() }' | grep -v ' 0$'
Easily add any number of attributes to the output. If you want to expand it in the future, you simply add more entries to the awk command for each attribute required as follows:, , p["ATTR1"], p["ATTR2"]
Using MAXDEPTH as an example:
echo "DIS QL(*) WHERE(CURDEPTH GT 0)" | runmqsc <qmgr> | sed -e 's/\((.*)\) *\(.*\)/\1\ \2/g' -e 's/^ *\([AZ][AZ]*[(][^)][^)]*[)]\)/\1/g' -e 's/^\(AMQ[0-9][0-9]*:\).*$/\1/g' | awk -F '[()]' -v OFS=" " 'function printValues() { if ("QUEUE" in p) { print p["QUEUE"], p["CURDEPTH"], p["MAXDEPTH"] } } /AMQ8409:/ { printValues(); for (i in p) { delete p[i] }; next } { p[$1] = $2 } END { printValues() }'
Please note that this answer and possibly others will have a problem if the attribute itself has a built-in bracket, this is possible in the DESCR field of the queue and is true for various other fields for other types of objects. One common example is the CONNAME attribute for CHANNEL . CONNAME uses the hostname(port) format, therefore it is displayed as CONNAME(hostname(port)) .