Hi piggy213,
The top line (#!/usr/bin/awk -f) is called the 'shebang line'.
The shebang line tells the Unix/Linux environment that this is specifically an awk script (as opposed to a Bourne-shell or c-shell script, for example). You need a different shebang line for awk, c-shell, Bourne-shell, Perl, and so on.
The shebang line also tells the Unix/Linux environment how to find the awk program that will be responsible for executing the awk script.
The path that you should use for the shebang line may be different from what I wrote (ie: /usr/bin/awk). To make sure you are using the correct path on your machine, type:
% which awk
You might see something like this:
% which awk
/bin/awk
In that case, you could change the shebang line to:
#!/bin/awk -f
The '-f' switch is an instruction to the awk program that you must include after the shebang line. Anyway, think of it as having a special meaning for awk. If there is a '-f' switch for c-shell, it would probably have an entirely different meaning. So, don't use it with a c-shell script just because I used it with an awk script.
I am guessing that you might want to call the script I created above (log.awk) from a c-shell script. Here is a hint how to do it:
#!/usr/bin/csh
Do something in the c-shell language...
set SEARCHDATE = "Mon Sep 30"
Do something else in the c-shell language...
awk ' BEGIN{ "date '+%a %b %d'" | getline date; }
$0 ~ date {
print $0;
while( (getline) > 0 )
{
if( $0 ~ /error/ )
{
print $0;
exit;
}
}
}' date=$SEARCHDATE log.awk
do some other stuff in the c-shell language...
Hope this answers your questions,
Grant