2

I have an executable awk program that only operates on files with a certain name. How can I make it always open then same file so I don't have to type the name every time?

I want to be able to write

$ ./prog.awk

instead of

$ ./prog.awk filename

1 Answer 1

3

You can manipulate the ARGC and ARGV variables in the BEGIN block to change the files your program will read.

#!/usr/bin/awk -f

BEGIN {
    ARGC = 2
    ARGV[1] = filename
}

Setting ARGV[1] will make awk read that file, and setting ARGC to 2 will cause awk to ignore any other files passed on the command line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.