Issue
I am having hard time try figure out how to pars two values from below output:
CHANNEL(SYSTEM.DEF.SVRCONN) CHLTYPE(SVRCONN)
ALTDATE(2022-11-06) ALTTIME(21.48.22)
CERTLABL( ) COMPHDR(NONE)
COMPMSG(NONE) DESCR( )
DISCINT(0) HBINT(300)
KAINT(AUTO) MAXINST(999999999)
MAXINSTC(999999999) MAXMSGL(4194304)
MCAUSER( ) MONCHL(QMGR)
RCVDATA( ) RCVEXIT( )
SCYDATA( ) SCYEXIT( )
SENDDATA( ) SENDEXIT( )
SHARECNV(10) SSLCAUTH(REQUIRED)
SSLCIPH( ) SSLPEER( )
TRPTYPE(TCP)
I have tired this, but does not work.
echo 'dis CHANNEL(SYSTEM.DEF.SVRCONN)' | runmqsc QREP311 | sed -n 's/.*\(CHLTYPE.*\).*\(MCAUSER.*\)/\1 \2/p'
Desire or expecting output like this:
CHLTYPE(SVRCONN) MCAUSER( )
Solution
Using gnu awk you could use:
$ awk '{if (match($0,/CHLTYPE([^)]+))|MCAUSER([^)]+))/,m)) f? f=f" "m[0]: f=m[0]} END{print f}' file
CHLTYPE(SVRCONN) MCAUSER( )
If either of the two patterns of interest are found (so CHLTYPE
and MCAUSER
with whatever in brackets) then build an output string with the match.
Answered By - Paolo Answer Checked By - Timothy Miller (WPSolving Admin)