user3164754 user3164754 - 3 months ago 11
Bash Question

Print part of an array or a file and sort in shell

I have a text file as follows

1 : dis conn(*) type(CONN) all where(UOWLOG ne '')
AMQ8276: Display Connection details.
CONN(AE1CA9572C47D822)
EXTCONN(414D51434D5147575032202020202020)
TYPE(CONN)
PID(9098) TID(503215)
APPLDESC(WebSphere MQ Channel)
APPLTAG(WebSphere MQ Client for Java)
APPLTYPE(USER) ASTATE(NONE)
CHANNEL(ABIS.CLIENT) CLIENTID( )
CONNAME(101.54.151.80)
CONNOPTS(MQCNO_HANDLE_SHARE_BLOCK,MQCNO_FASTPATH_BINDING)
USERID(malth) UOWLOG(S0599315.LOG)
UOWSTDA(2016-08-16) UOWSTTI(11.06.38)
UOWLOGDA(2016-08-16) UOWLOGTI(11.06.38)
URTYPE(QMGR)
EXTURID(XA_FORMATID[] XA_GTRID[] XA_BQUAL[])
QMURID(0.190537069) UOWSTATE(ACTIVE)
AMQ8276: Display Connection details.
CONN(AE1CA957D787F429)
EXTCONN(414D51434D5147575032202020202020)
TYPE(CONN)
PID(28292) TID(1519092)
APPLDESC(WebSphere MQ Channel)
APPLTAG(WebSphere MQ Client for Java)
APPLTYPE(USER) ASTATE(NONE)
CHANNEL(SB.CLIENT) CLIENTID( )
CONNAME(101.54.151.119)
CONNOPTS(MQCNO_HANDLE_SHARE_BLOCK,MQCNO_FASTPATH_BINDING)
USERID(sbp) UOWLOG(S0599317.LOG)
UOWSTDA(2016-08-16) UOWSTTI(11.07.38)
UOWLOGDA(2016-08-16) UOWLOGTI(11.07.38)
URTYPE(QMGR)
EXTURID(XA_FORMATID[] XA_GTRID[] XA_BQUAL[])
QMURID(0.190520281) UOWSTATE(ACTIVE)
AMQ8276: Display Connection details.
CONN(2CC7AE57CE8E6221)
EXTCONN(414D51434D5147575032202020202020)
TYPE(CONN)
PID(22400) TID(647335)
APPLDESC(WebSphere MQ Channel)
APPLTAG(WebSphere MQ Client for Java)
APPLTYPE(USER) ASTATE(NONE)
CHANNEL(U90785.CBM.CLIENT) CLIENTID( )
CONNAME(101.54.163.37)
CONNOPTS(MQCNO_HANDLE_SHARE_BLOCK,MQCNO_FASTPATH_BINDING)
USERID(machlth) UOWLOG(S0599317.LOG)
UOWSTDA(2016-08-16) UOWSTTI(11.07.40)
UOWLOGDA(2016-08-16) UOWLOGTI(11.07.40)
URTYPE(QMGR)
EXTURID(XA_FORMATID[] XA_GTRID[] XA_BQUAL[])
QMURID(0.190574800) UOWSTATE(ACTIVE)
AMQ8276: Display Connection details.
CONN(2CC7AE571BF0B721)
EXTCONN(414D51434D5147575032202020202020)
TYPE(CONN)
PID(22210) TID(1069968)
APPLDESC(WebSphere MQ Channel)
APPLTAG(WebSphere MQ Client for Java)
APPLTYPE(USER) ASTATE(NONE)
CHANNEL(APP.CLIENT) CLIENTID( )
CONNAME(101.54.163.127)
CONNOPTS(MQCNO_HANDLE_SHARE_BLOCK,MQCNO_FASTPATH_BINDING)
USERID(apsp) UOWLOG(S0599317.LOG)
UOWSTDA(2016-08-16) UOWSTTI(11.07.29)
UOWLOGDA(2016-08-16) UOWLOGTI(11.07.29)
URTYPE(QMGR)
EXTURID(XA_FORMATID[] XA_GTRID[] XA_BQUAL[])


Now i want my output to to show

ABIS.CLIENT,101.54.151.80,malth,S0599315.LOG,11.06.38
APP.CLIENT,101.54.163.127,apsp,S0599317.LOG,11.07.29
SB.CLIENT,101.54.151.119,sbp,S0599317.LOG,11.07.38
CBM.CLIENT,101.54.163.37,machlth,S0599317.LOG,11.07.40


so basically, get the channel name, conname, userid,UUOWLOG and UOWLOGTI and sort it all in the end by UOWLOGTI.
I am trying to do this in shell.

I have tried using
awk
but can't seem to get the desired output.

cat UOWLOG.txt|awk -vRS="" 'BEGIN{printf ""}/\<'AMQ8276'\>/^CHANNEL{printf $0 RT}'

I get errors when i try different options in awk.
Please help.

Answer

all can be done in awk but perhaps easier with a chain of tools

$ grep -oP '(CHANNEL|CONNAME|USERID|UOWLOG|UOWLOGTI)\(.*?\)' file | 
  awk -F'[()]' '{ORS=NR%5?",":RS; print $2}' | 
  sort -t, -k5

ABIS.CLIENT,101.54.151.80,malth,S0599315.LOG,11.06.38
APP.CLIENT,101.54.163.127,apsp,S0599317.LOG,11.07.29
SB.CLIENT,101.54.151.119,sbp,S0599317.LOG,11.07.38
U90785.CBM.CLIENT,101.54.163.37,machlth,S0599317.LOG,11.07.40
Comments