Awk Functions

Hi all.
I have a simple shell script shown below which calls an awk function and then print valid or invalid depending on the return value:

#!/bin/sh

cat file.CSV| nawk -f validate '
BEGIN { FS=","; counter=0}

{
        FS=",";
        gsub("\"","")
        valid=validate($1);
        if (valid == 1)
                print "INVALID";
        else
                print "VALID"
        
}

When i run this script I get no output at all. The script runs but nothing seems to happen. However when i include the function, shown below, in the script it runs as expected.

function validate(object)
{
        #populates an array List 
        if(object in stationList){
                return 0;}
        else{
                return 1;}
}

I dont want to have to include the functions code in every script I write and I was under the impression that using -f validate when starting nawk would let me then call the function from within my script.
Any ideas or help with this would be appreciated.

Thanks

Your main awk script must be in a file.

nawk -f  validate.awk -f main.awk file.CSV

validate.awk :

function validate(object)
{
        #populates an array List 
        if(object in stationList){
                return 0;}
        else{
                return 1;}
}

main.awk :

BEGIN { FS=","; counter=0}

{
        FS=",";
        gsub("\"","")
        valid=validate($1);
        if (valid == 1)
                print "INVALID";
        else
                print "VALID"
        
}

Jean-Pierre.

Thanks for your reply.

Does this mean it is not possible to call my function from inside a shell script?
I had hoped I could call it in an awk section of a shell script?