jonseager jonseager - 7 months ago 17
Bash Question

GAWK Script - Print filename in BEGIN section

I am writing a gawk script that begins

#!/bin/gawk -f
BEGIN { print FILENAME }


I am calling the file via
./script file1.html
but the script just returns nothing. Any ideas?

Answer

you can use ARGV[1] instead of FILENAME if you really want to use it in BEGIN block

awk 'BEGIN{print ARGV[1]}' file
Comments