awk statements involving several loops

Dear team,

The below is the input file.

Here need to run loop in awk which will check for "shaNmfTode=DL-$x,shaNmfTluster=myNmfTluster" where DL- has variable value started from 3 to 8. and CS has variable started from 1 to 2. after checking each and as per below two lines each block or array if AdmState found deffer from CMTOCKED and OperState deffer from TNMDLED. The output will be printed ..

like below

awk 'BEGIN{print "Checking Nmf cluster state:..."}{a[++i]=$0;}END{for(x=3;x>8;x++) {for (k=1;k<3;k++) {if (a[k]~"shaNmfTode=DL-$x,shaNmfTluster=myNmfTluster") {a[x+y] } {if (a[x+y]~"CMTOCKED"  || [x+y]~TNMDLED"){print ""} else { print a[x+y]}}}' CMWSTA | grep .> CMWSTA_stat

Its not working.. Thanks

... is not something people can start analysing / debugging a problem upon. Nor is your code as presented.

First step is get rid of the syntax errors encountered.

Apply adequate structuring like indenting and block building - your choice, but stick to it - to improve readabiltiy and understandability. Same holds for your free text, BTW,

Show results (even if non-satisfying; explain why, then) and error messages / warning, whatever applies.

I don't see a CS variable anywhere in your code or data, nor do I see a value of 2. A string "AdmState" can't be found. Why should the block with shaNmfTode=DL-8 be selected for printout, and where do the AdminState=SOCKED(1) and OperState=DWNLED(1) values come from?

1 Like