mercredi 29 mars 2017

AWK syntax error while using the IF statement

I am very new to AWK although I have previously used the command prompt/terminal.

I have this script below where I am creating subsets of data based on Country Code and State Code. But I get a syntax error.

BEGIN{
   FS = "\t"
   OFS = "\t"
   }

 # Subset data from the states you need for all years 
 if ($5 == "IN-GA" || $5 == "IN-DD" || $5 == "IN-DN" || $5 == "IN-KA" || $5 == "IN-KL" || $5 == "IN-MH" || $5 == "IN-TN" || $5 == "IN-GJ")'{
        if (substr($17, 1, 4) == "2000"){
            print $5, $12, $13, $14, $15, $16, $17, $22, $23, $24, $25, $26, $28 > "Y2000_India_sampling_output.txt"
        }
    }   

On Cygwin, I refer to the script and I run the below lines of code and you see the syntax error immediately:

$ gawk -f sampling_India.awk sampling_relFeb-2017.txt
gawk: sampling_India.awk:20:  gawk if ($5 == "IN-GA" || $5 == "IN-DD" || $5 == "IN-DN" || $5 == "IN-KA" || $5 == "IN-KL" || $5 == "IN-MH" || $5 == "IN-TN" || $5 == "IN-GJ"){
gawk: sampling_India.awk:20:       ^ syntax error

Any thoughts?

Aucun commentaire:

Enregistrer un commentaire