0

Hi I've got a awk script and keep getting the error ^ syntax error. i don't understand where it is, here is the code :

BEGIN { 
FS=" " 
COUNT=0 
} 

m = substr($5,4,2)
if ($6 == DAY && m == MONTH)
{
COUNT++
}

END { 
print DAY","MONTH 
}   

here the line i write in my script using the awk file:

cat accident.txt | awk -v DAYS=$j -v MONTH=$i -f count-by-week-and-month.awk > $i.txt
1
  • What is the exact error message you're getting? Commented Dec 8, 2013 at 17:24

1 Answer 1

2

You have some error with {}, try this:

BEGIN { 
FS=" " 
COUNT=0 
} 

{
m = substr($5,4,2)
if ($6 == DAY && m == MONTH)
    COUNT++
}

END { 
print DAY","MONTH 
}  

Shorten version (begin block is not needed. FS is default space, and counter is zero)

{ m=substr($5,4,2)
if ($6 == DAY && m == MONTH)
    COUNT++}
END { 
    print DAY","MONTH}  
Sign up to request clarification or add additional context in comments.

1 Comment

The if needs to be within brackets. You could even shorten it some to what I have added.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.