Home > Archive > AWK > November 2006 > executing END { } function without an input file
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
executing END { } function without an input file
|
|
| p.boddupalli@gmail.com 2006-11-21, 9:56 pm |
| Hello,
To be able to generate argument-specific output, my awk script reads
as:
# genldscript.awk
END {
...
printf ("%s.mod : \n", module);
...
}
and is invoked as:
awk -f genldscript.awk module=usb
Since there in no input file, the script waits for ctrl-d on the
command line to print the output. The print statements are in END { }
as argument values are not available in BEGIN { }.
Can the script be made to execute END function without waiting for
input and without having to specify an input file as in:
awk -f genldscript.awk module=usb <somefile>
thank you,
Pra .
| |
|
| p.boddupalli@gmail.com belched the following on 11/21/2006 7:53 PM:
> Hello,
>
> To be able to generate argument-specific output, my awk script reads
> as:
>
> # genldscript.awk
> END {
> ...
> printf ("%s.mod : \n", module);
> ...
> }
>
> and is invoked as:
>
> awk -f genldscript.awk module=usb
>
> Since there in no input file, the script waits for ctrl-d on the
> command line to print the output. The print statements are in END { }
> as argument values are not available in BEGIN { }.
>
> Can the script be made to execute END function without waiting for
> input and without having to specify an input file as in:
>
> awk -f genldscript.awk module=usb <somefile>
>
> thank you,
> Pra .
>
awk -v module=usb -f genldscript.awk
makes variable available in the BEGIN section
awk -f genldscript.awk module=usb </dev/null
will generate EOF without having to input
--
pop is Mark
I Stopped to think but forgot to start again.
--
| |
| Ed Morton 2006-11-22, 6:56 pm |
| pop wrote:
> p.boddupalli@gmail.com belched the following on 11/21/2006 7:53 PM:
>
That's why you should set variables using -v and leave the arguments as
file names unless you have some need to change/set a variable value
between files.
[color=darkred]
>
> awk -v module=usb -f genldscript.awk
> makes variable available in the BEGIN section
That's the most sensible way to do it.
> awk -f genldscript.awk module=usb </dev/null
> will generate EOF without having to input
>
or just add "BEGIN{exit}" to the start of your script.
Ed.
|
|
|
|
|