If I want to pass a parameter to an awk script file, how can I do that ?
#!/usr/bin/awk -f {print $1}
Here I want to print the first argument
You can use -v as a command-line option to provide a variable to the script:
-v
Say we have a file script.awk like this:
BEGIN {print "I got the var:", my_var}
Then we run it like this:
$ awk -v my_var="hello this is me" -f script.awk I got the var: hello this is me