Well, I managed to tame sed
and grep
enough to get a working solution that can handle the two-or-three line output. It's very specific to this situation but the concepts could be applied to similar scenarios.
In short, I did not find a way to influence the output format of the display command, but did find a way to process it.
The following QShell command (run it with STRQSH
) gives me a CSV of queue, current depth, maximum depth. I then use CPYFRMIMPF to move this into a DB2 file for processing.
CHGVAR VAR(&QSH) VALUE('+
echo "dis qlocal(*) curdepth maxdepth"
| /QSYS.LIB/QMQM.LIB/RUNMQSC.PGM ''' |< &QMGR |< ''' +
| grep ''[A-Z]\{4,8\}('' +
| sed -e ''/QUEUE([-A-Za-z0-9._\/]*)$/{N;s/\n//;}'' +
-e ''/TYPE([-A-Za-z0-9._\/]*)$/{N;s/\n//;}'' +
-e ''/CURDEPTH([0-9]*)$/{N;s/\n//;}'' +
-e ''s/^\ \ *//'' +
-e ''s/\ \ */,/g'' +
-e ''s/QUEUE[(]\([-A-Za-z0-9._\/]*\)[)]/"\1"/'' +
-e ''s/TYPE[(][-A-Za-z0-9._\/]*[)],//'' +
-e ''s/CURDEPTH[(]\([0-9]*\)[)]/\1/'' +
-e ''s/MAXDEPTH[(]\([0-9]*\)[)]/\1/'' +
| grep -v ''SYSTEM.'' +
> /tmp/mqqueuests.csv+
')
It allows for queue names with alphanumeric and . - _ /
characters.
The fundamental solution to the problem of the variable numbers of lines lies in finding lines that do not end with MAXDEPTH( )
and removing the subsequent linefeed by means of the N
command in sed
. This pulls the next line of the file into the pattern buffer, where the linefeed can be stripped.