AmyC
AmyC

Reputation: 9

AWK parse error at END

I keep getting a parse error in my code at the end

C:\Users\user\Documents\hafwork\hafLatest\CRM>AWK.EXE -f testking123.awk sample.txt
awk: testking123.awk:85: END{
awk: testking123.awk:85: ^ parse error
awk: testking123.awk:90:
awk: testking123.awk:90: ^ parse error

This is my code:

BEGIN{

FS= "|"
countA=CountB=0;

}

{

id=substr($2,1,1);
++file[id]




if ($3 == "P")
{
if(countB==0){
for(dupes in B)
print B[dupes] > "Bdupes.txt"
}

else if(countA==0){
for(dupes in A)
print A[dupes] > "Adupes.txt"
}

else if(countA==countB)
i=1
while(i<countA){

printA[i] > "mixdupes.txt"
printB[i] > "mixdupes.txt"

}


if(A<B && A!=0){

i=1
while(i<(A+1)){
printA[i] > "mixdupes.txt"
printB[i] > "mixdupes.txt"
}

i=A+1
while(i<(B+1)){
print B[i]> "Bdupes.txt"


  if(id=="A"){
    A[1]=$0
    countA=1;
    countB=0;

    }

  else if (id=="B"){
    B[1]=$0
    countA=0;
    countB=1;
    }
  }
elseif ($3 == "C")
{

   if(id=="A"){
    countA++;
    A[countA]=$0
    }

else if(id=="B"){
   countB++;
    B[countB]=$0
    }






}
}

END{

for (file_id in file)
print file_id ":", file[file_id]

}

Could anyone tell me why this is? I have tried removing spaces etc. Im not sure whether its to do with just the end of the script or if something is wrong within the script. Pretty new to AWK so not 100% sure on it. TIA

Upvotes: 0

Views: 200

Answers (1)

Kent
Kent

Reputation: 195179

usually this happens because you have unmatched { or }.

I just copied your code in my vim and did a gg=G,

you are missing two closing }s.

You have 15 { in total, but only 13 }.

Upvotes: 1

Related Questions