Pass parameter to an awk script file

In awk $1 references the first field in a record not the first argument like it does in bash. You need to use ARGV for this, check out here for the offical word.

Script:

#!/bin/awk -f

BEGIN{
    print "AWK Script"
    print ARGV[1]
}

Demo:

$ ./script.awk "Passed in using ARGV"
AWK Script
Passed in using ARGV

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)