From: Harry on 25 Feb 2010 16:31 On Feb 25, 12:48 pm, Ed Morton <mortons...(a)gmail.com> wrote: [snip] > $ awk 'BEGIN{RS="";FS="\n"} > /SSLCAUTH\(REQUIRED\)/{ > for (i=1;i<=NF;i++) > if ($i ~ /DEFINE|SSLCAUTH|SSLCIPH/) > print $i > print ""}' file > > DEFINE CHANNEL ('AAA.SVRCONN') CHLTYPE(SVRCONN) + > SSLCAUTH(REQUIRED) + > SSLCIPH(' ') + Ed, this one works great! My cmd now look like this. $ find . -type f -exec awk 'BEGIN{RS="";FS="\n"} /SSLCAUTH\(REQUIRED \)/ { for (i=1;i<=NF;i++) if ($i ~ /DEFINE|SSLCAUTH|SSLCIPH/) print $i}' {} \; BTW, each hostX/Q_ManagerY.log file may contain mutiple CHANNEL definition with SSLCAUTH(REQUIRED). How can I display the file names as well ? For example, associate ../host1/Q_MANAGER1.log ../host1/Q_MANAGER2.log ../host2/Q_MANAGER3.log .... with .... DEFINE CHANNEL (CH_A) CHLTYPE(CLUSRCVR) + SSLCAUTH(REQUIRED) + SSLCIPH(' ') + DEFINE CHANNEL ('CH_B') CHLTYPE(CLUSRCVR) + SSLCAUTH(REQUIRED) + SSLCIPH(' ') + DEFINE CHANNEL ('CH_C') CHLTYPE(SVRCONN) + SSLCAUTH(REQUIRED) + SSLCIPH(' ') + ....
From: John W. Krahn on 25 Feb 2010 16:36 Harry wrote: > I have about 30 text files containing some MQ object definitions. > I want to locate some CHANNEL definitions with a pattern > "SSLCAUTH(REQUIRED)". > > For example: > > $ find . -type f -exec grep -l SSLCAUTH\(REQUIRED\) {} \; > ./host1/Q_MANAGER1.log > ./host1/Q_MANAGER2.log > ./host2/Q_MANAGER3.log > ./host2/Q_MANAGER4.log > ./host3/Q_MANAGER5.log > ./host3/Q_MANAGER6.log > ... > > The text before and after the pattern are like this : > > DEFINE CHANNEL ('AAA.SVRCONN') CHLTYPE(SVRCONN) + > * ALTDATE (2009-07-24) + > * ALTTIME (23.03.53) + > TRPTYPE(TCP) + > DESCR(' ') + > HBINT(300) + > MAXMSGL(4194304) + > MCAUSER(' ') + > RCVDATA(' ') + > RCVEXIT(' ') + > SCYDATA(' ') + > SCYEXIT(' ') + > SENDDATA(' ') + > SENDEXIT(' ') + > SSLCAUTH(REQUIRED) + > SSLCIPH(' ') + > SSLPEER(' ') + > KAINT(AUTO) + > MONCHL(QMGR) + > COMPMSG(NONE) + > COMPHDR(NONE) + > REPLACE > > DEFINE QUEUE <blablabla> > ... > > What I want is a shell cmd that can print (for each channel > definition inside a Q_MANAGER log) : > (1) the DEFINE CHANNEL line before the pattern > (2) the SSLCAUTH(REQUIRED) line > (3) the SSLCIPH line $ echo "DEFINE CHANNEL ('AAA.SVRCONN') CHLTYPE(SVRCONN) + * ALTDATE (2009-07-24) + * ALTTIME (23.03.53) + TRPTYPE(TCP) + DESCR(' ') + HBINT(300) + MAXMSGL(4194304) + MCAUSER(' ') + RCVDATA(' ') + RCVEXIT(' ') + SCYDATA(' ') + SCYEXIT(' ') + SENDDATA(' ') + SENDEXIT(' ') + SSLCAUTH(REQUIRED) + SSLCIPH(' ') + SSLPEER(' ') + KAINT(AUTO) + MONCHL(QMGR) + COMPMSG(NONE) + COMPHDR(NONE) + REPLACE DEFINE QUEUE <blablabla> ...." | perl -ne'$_ .= <> and redo if s/\+$//; print grep /DEFINE CHANNEL|SSLCAUTH\(REQUIRED\)|SSLCIPH/, /.*\n/g' DEFINE CHANNEL ('AAA.SVRCONN') CHLTYPE(SVRCONN) SSLCAUTH(REQUIRED) SSLCIPH(' ') John -- The programmer is fighting against the two most destructive forces in the universe: entropy and human stupidity. -- Damian Conway
From: Harry331 on 25 Feb 2010 23:04 Harry wrote... >My cmd now look like this. >$ find . -type f -exec awk 'BEGIN{RS=3D"";FS=3D"\n"} /SSLCAUTH\(REQUIRED >\)/ >{ for (i=3D1;i<=3DNF;i++) if ($i ~ /DEFINE|SSLCAUTH|SSLCIPH/) print >$i}' {} \; > >BTW, each hostX/Q_ManagerY.log file may contain mutiple CHANNEL >definition with SSLCAUTH(REQUIRED). >How can I display the file names as well ? > > >For example, associate >./host1/Q_MANAGER1.log >./host1/Q_MANAGER2.log >./host2/Q_MANAGER3.log >... > >with >... >DEFINE CHANNEL (CH_A) CHLTYPE(CLUSRCVR) + > SSLCAUTH(REQUIRED) + > SSLCIPH(' ') + >DEFINE CHANNEL ('CH_B') CHLTYPE(CLUSRCVR) + > SSLCAUTH(REQUIRED) + > SSLCIPH(' ') + >DEFINE CHANNEL ('CH_C') CHLTYPE(SVRCONN) + > SSLCAUTH(REQUIRED) + > SSLCIPH(' ') + Here is my latest revision. find . -type f -exec echo \; -exec echo {} \; -exec awk 'BEGIN{RS="";FS="\n"} /SSLCAUTH\(REQUIRED\)/ { for (i=1;i<=NF;i++) if ($i ~ /DEFINE|SSLCAUTH|SSLCIPH/) print $i}' {} \;
From: Ed Morton on 26 Feb 2010 08:49 On 2/25/2010 10:04 PM, Harry331 wrote: > Harry wrote... <snip> >> How can I display the file names as well ? <snip> > Here is my latest revision. > > find . -type f -exec echo \; -exec echo {} \; -exec > awk 'BEGIN{RS="";FS="\n"} /SSLCAUTH\(REQUIRED\)/ { for > (i=1;i<=NF;i++) if ($i ~ /DEFINE|SSLCAUTH|SSLCIPH/) print > $i}' {} \; > > In awk the "FILENAME" variable contains (surprise!) the file name so depending on how you want your output to be formatted you could do something like either of these: awk 'BEGIN{RS="";FS="\n"} /SSLCAUTH\(REQUIRED\)/ { for (i=1;i<=NF;i++) if ($i ~ /DEFINE|SSLCAUTH|SSLCIPH/) print FILENAME,$i print "" }' awk 'BEGIN{RS="";FS="\n"} /SSLCAUTH\(REQUIRED\)/ { print FILENAME for (i=1;i<=NF;i++) if ($i ~ /DEFINE|SSLCAUTH|SSLCIPH/) print $i print "" }' I also threw in an extra print "" to give you a blank line between records in case that's useful for separating them. Regards, Ed.
From: Ed Morton on 26 Feb 2010 10:45 On 2/25/2010 3:36 PM, John W. Krahn wrote: > Harry wrote: >> I have about 30 text files containing some MQ object definitions. >> I want to locate some CHANNEL definitions with a pattern >> "SSLCAUTH(REQUIRED)". >> >> For example: >> >> $ find . -type f -exec grep -l SSLCAUTH\(REQUIRED\) {} \; >> ./host1/Q_MANAGER1.log >> ./host1/Q_MANAGER2.log >> ./host2/Q_MANAGER3.log >> ./host2/Q_MANAGER4.log >> ./host3/Q_MANAGER5.log >> ./host3/Q_MANAGER6.log >> ... >> >> The text before and after the pattern are like this : >> >> DEFINE CHANNEL ('AAA.SVRCONN') CHLTYPE(SVRCONN) + >> * ALTDATE (2009-07-24) + >> * ALTTIME (23.03.53) + >> TRPTYPE(TCP) + >> DESCR(' ') + >> HBINT(300) + >> MAXMSGL(4194304) + >> MCAUSER(' ') + >> RCVDATA(' ') + >> RCVEXIT(' ') + >> SCYDATA(' ') + >> SCYEXIT(' ') + >> SENDDATA(' ') + >> SENDEXIT(' ') + >> SSLCAUTH(REQUIRED) + >> SSLCIPH(' ') + >> SSLPEER(' ') + >> KAINT(AUTO) + >> MONCHL(QMGR) + >> COMPMSG(NONE) + >> COMPHDR(NONE) + >> REPLACE >> >> DEFINE QUEUE <blablabla> >> ... >> >> What I want is a shell cmd that can print (for each channel >> definition inside a Q_MANAGER log) : >> (1) the DEFINE CHANNEL line before the pattern >> (2) the SSLCAUTH(REQUIRED) line >> (3) the SSLCIPH line > > $ echo "DEFINE CHANNEL ('AAA.SVRCONN') CHLTYPE(SVRCONN) + > * ALTDATE (2009-07-24) + > * ALTTIME (23.03.53) + > TRPTYPE(TCP) + > DESCR(' ') + > HBINT(300) + > MAXMSGL(4194304) + > MCAUSER(' ') + > RCVDATA(' ') + > RCVEXIT(' ') + > SCYDATA(' ') + > SCYEXIT(' ') + > SENDDATA(' ') + > SENDEXIT(' ') + > SSLCAUTH(REQUIRED) + > SSLCIPH(' ') + > SSLPEER(' ') + > KAINT(AUTO) + > MONCHL(QMGR) + > COMPMSG(NONE) + > COMPHDR(NONE) + > REPLACE > > DEFINE QUEUE <blablabla> > ..." | perl -ne'$_ .= <> and redo if s/\+$//; print grep /DEFINE > CHANNEL|SSLCAUTH\(REQUIRED\)|SSLCIPH/, /.*\n/g' > DEFINE CHANNEL ('AAA.SVRCONN') CHLTYPE(SVRCONN) > SSLCAUTH(REQUIRED) > SSLCIPH(' ') > Please don't take this as a knock against perl as it's not intended that way, I'm just genuinely curious. Maybe it's just me but I find the syntax of: perl -ne'$_ .= <> and redo if s/\+$//; print grep /DEFINE CHANNEL|SSLCAUTH\(REQUIRED\)|SSLCIPH/, /.*\n/g' very unintuitive compared to this awk syntax to produce the same output: awk 'BEGIN{RS="";FS="\n"} /SSLCAUTH\(REQUIRED\)/{ for (i=1;i<=NF;i++) if ($i ~ /DEFINE CHANNEL|SSLCAUTH|SSLCIPH/) print $i }' Is the perl syntax you used above just a choice you made for the sake of brevity and in reality it's possible to do the job in perl using a syntax that's similar to the awk one? If so, what would that look like? I suppose I could do something similar to the perl syntax above in GNU awk like: gawk -v RS= '$0!=($0=gensub(/(DEFINE CHANNEL[^\n]*).*(SSLCAUTH\(REQUIRED\)).*(SSLCIPH[^\n]*).*/,"\\1\n\\2\n\\3\n",""))' but in reality I wouldn't for the sake of clarity and portability to other awks. Ed.
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: jmanage start/stop init.d bash script Next: Escaping regexp meta characters |