LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   awk question about BEGIN patttern (https://www.linuxquestions.org/questions/linux-newbie-8/awk-question-about-begin-patttern-604921/)

jgrfilho 12-06-2007 08:02 AM

awk question about BEGIN patttern
 
I have a awk script with the following BEGIN pattern

BEGIN { upper = "PNBRQK"
lower = "pnbrqk"
getline < "lance1.tmp"
cor = substr($0,77,1)
}

I ca use cor inside other patterns when I run the script over lance1.tmp but I woul like to use it when I run the script over other files. How can I do that.

Thanks in advance for any help

Gaspar

cmnorton 12-06-2007 05:40 PM

Use ARGV and ARGC
 
awk -f your-script.awk name-of-file-to-process

BEGIN { upper = "PNBRQK"
lower = "pnbrqk"
getline < ARGV[1]
cor = substr($0,77,1)
}

ARGV[0] contains "awk"

Use ARGC to see that you have two parameters, one for "awk" and one for your file name.


All times are GMT -5. The time now is 02:01 PM.