I have a task to write a script that will filter an input from an MQ runmqsc command and redirect the output into another file. I have been working around using many other Linux commands piped together and it seems to work just fine in Linux, but my manager needs to run the script on an AIX system, so UNIX operating system. I was made aware that many commands that run fine on Linux or get the job done in Linux will produce a totally different output on UNIX or UNIX-based systems. The output from the runmqsc command looks like this:
5724-H72 (C) Copyright IBM Corp. 1994, 2009. ALL RIGHTS RESERVED.
Starting MQSC for queue manager CNUMQ02B.
1 : DISPLAY QLOCAL(*) CURDEPTH
AMQ8409: Display Queue details.
QUEUE(ADEXA.AOM.REPLY.MR.QL) TYPE(QLOCAL)
CURDEPTH(0)
AMQ8409: Display Queue details.
QUEUE(ADEXA.AOM.REPLY.QL) TYPE(QLOCAL)
CURDEPTH(0)
AMQ8409: Display Queue details.
QUEUE(ADEXA.ERROR.QL) TYPE(QLOCAL)
CURDEPTH(0)
AMQ8409: Display Queue details.
QUEUE(ADEXA.FACT.OUT.QL) TYPE(QLOCAL)
CURDEPTH(0)
AMQ8409: Display Queue details.
QUEUE(ADW.REMAN.XREF.ERR.QL) TYPE(QLOCAL)
CURDEPTH(14)
AMQ8409: Display Queue details.
QUEUE(SAPNA.MESS.CRITICAL.CLASS.RESUME.QL)
TYPE(QLOCAL) CURDEPTH(123)
One MQSC command read.
No commands have a syntax error.
All valid MQSC commands were processed.
What I basically need to do is only display the name of the queue, a whitespace, and then the queue depth on the same line, with no trailing whitespaces and no newline characters at the beginning or end of file, so that it will resemble a csv file with the whitespace as the separator. I also need to filter out queues that have a queue depth equal to 0, so the output will look like this:
ADW.REMAN.XREF.ERR.QL 14
As I said I tried many commands on Linux, but I have a lack of knowledge of what commands and flags actually work more or less the same on UNIX and Linux, and my manager wants this today, so if by any chance you read this I ask that you at least guide me what to use to try working it out :) Thanks.
This is what I wrote in Linux:
head -n -3 "$1" |
tail -n +6 |
sed '/AMQ8409: Display Queue details./d' |
sed 's/TYPE(QLOCAL)//g' |
tr -d ' \t\r\f' |
awk 'NR%2{printf "%s ",$0;next;}1' |
sed '/CURDEPTH(0)/d' |
awk '{gsub(/QUEUE(/, ""); gsub(/CURDEPTH(/, ""); gsub(/)/, ""); print}' |
sort -nk2
Try this simpler command..
sed -n -e 's/.*QUEUE(\([^)]*\)).*/\1/p' -e 's/.*CURDEPTH(\([0-9]*\)).*/\1/p' \
| paste -d ' ' - - \
| grep -v ' 0$'
Here's one that doesn't use gsub
:
awk -F "[()]" '/QUEUE/ {quename=$2} /CURDEPTH\(/ {print quename, $2} '
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With