awk statements involving several loops


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers awk statements involving several loops
# 1  
Old 03-03-2020
awk statements involving several loops

Dear team,


The below is the input file.


Quote:
cat CMWSTA
# cat CMWSTA

shaNmfTode=DL-3,shaNmfTluster=myNmfTluster
AdminState=CMTOCKED(1)
OperState=TNMDLED(1)
shaNmfTode=DL-4,shaNmfTluster=myNmfTluster
AdminState=CMTOCKED(1)
OperState=TNMDLED(1)
shaNmfTode=DL-5,shaNmfTluster=myNmfTluster
AdminState=CMTOCKED(1)
OperState=TNMDLED(1)
shaNmfTode=DL-6,shaNmfTluster=myNmfTluster
AdminState=CMTOCKED(1)
OperState=TNMDLED(1)
shaNmfTode=DL-7,shaNmfTluster=myNmfTluster
AdminState=CMTOCKED(1)
OperState=TNMDLED(1)
shaNmfTode=DL-8,shaNmfTluster=myNmfTluster
AdminState=CMTOCKED(1)
OperState=TNMDLED(1)

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. after checking each and as per below two lines each block or array if AdminState found deffer from CMTOCKED and OperState deffer from TNMDLED. The output will be printed ..
Ideally this input file has status for DL below as CMTOCKED and TNMDLED. In case has different value that need to be printed along with corresponding DL(e.q shaNmfTode=DL-8,shaNmfTluster=myNmfTluster).



like below


Quote:
shaNmfTode=DL-8,shaNmfTluster=myNmfTluster
AdminState=SOCKED(1)
OperState=DWNLED(1)

Code:
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
# 2  
Old 03-03-2020
What's new compared to your other thread?


You even copied the syntax errors in your code sample?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

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... (1 Reply)
Discussion started by: shanul karim
1 Replies

2. Shell Programming and Scripting

awk with many if statements

Hi What is the right structure to use awk with multiple If statements The following code doesn't work # awk ' { A = $1 } END { for ( i = 1; i <= c; i++ ) { if ( A == 236 && A ==199... (7 Replies)
Discussion started by: khaled79
7 Replies

3. Shell Programming and Scripting

Nested awk Statements

Hello again everyone, yes, I'm back again for more help! So I'm attempting to read two separate files and generate some XML code from that. My current code is: BEGIN { print "<?xml version=\"1.0\" encoding=\"utf-8\">" print "<Export>" } { x=1; print "<section name=\"Query" NR "\">"... (5 Replies)
Discussion started by: Parrakarry
5 Replies

4. Shell Programming and Scripting

awk problem - combining awk statements

i have a datafile that has several lines that look like this: 2,dataflow,Sun Mar 17 16:50:01 2013,1363539001,2990,excelsheet,660,mortar,660,4 using the following command: awk -F, '{$3=strftime("%a %b %d %T %Y,%s",$3)}1' OFS=, $DATAFILE | egrep -v "\-OLDISSUES," | ${AWK} "/${MONTH} ${DAY}... (7 Replies)
Discussion started by: SkySmart
7 Replies

5. Shell Programming and Scripting

awk , conditional involving line and column

Dear All, I indeed your help for managing resarch data file. for example I have, data1.txt : type of atoms z vz Si 34 54 O 20 56 H 14 13 Si 40 17 O ... (11 Replies)
Discussion started by: ariesto
11 Replies

6. UNIX for Dummies Questions & Answers

Combine two awk statements into one

Hi, I have the following two awk statements which I'd like to consolidate into one by piping the output from the first into the second awk statement (rather than having to write kat.txt out to a file and then reading back in). awk 'BEGIN {FS=OFS=" "} {printf("%s ", $2);for (x=7; x<=10;... (3 Replies)
Discussion started by: kasan0
3 Replies

7. UNIX for Dummies Questions & Answers

AWK w/ if statements failing.

I'm converting some code from ksh on my macbook (Version M 1993-12-28 s+) to an older solaris machine with ksh 88. I can't seem to figure out this line, it worked on the new shell version. set -A combo -- $(for x in ${ImageIDs}; do nawk -v s=$x 'if($2 == s) getline ; getline if ($1 ==... (2 Replies)
Discussion started by: nerdcurious
2 Replies

8. Shell Programming and Scripting

Combine awk statements

I have an awk statement that works but I am calling awk twice and I know there has to be a way to combine the two statements into one. The purpose is to pull out just the ip address from loopback1. cat config.txt | nawk 'BEGIN {FS="\n"}{RS="!"}{if ( $0 ~ "interface loopback1" ) print$4}' | nawk... (5 Replies)
Discussion started by: numele
5 Replies

9. Shell Programming and Scripting

Help a newbie please with awk if else statements

Hi, Despite reading the Conditional Statements chapter in the O'Reilly Sed & Awk book several times and looking at numerous examples, I cannot for the life of me get any kind of if ... else statement to work in my awk scripts! My scripts work perfectly (as they are written at least) and do what... (4 Replies)
Discussion started by: jonathanm
4 Replies

10. Shell Programming and Scripting

While loops and awk

I am trying to make a script that will replace backslashes in a file, but only if the occurance is a pathname. In the file, there are a lot of regular expressions as well, so I'm trying to preserve the integrity of those regular expressions, but convert Windows relative paths. I'm using bash and... (1 Reply)
Discussion started by: Loriel
1 Replies
Login or Register to Ask a Question