Read input file with in awk script not through command line

Hi All,

Do we know how to read input file within awk script and send output toanother log file. All this needs to be in awk script, not in command line. I am running this awk through crontab.

 
Cat my.awk
#!/bin/awk -f
function test(var){
some code}
{
}
END
{
print"test code"
}

What do you want to achieve?
Just some simple redirection for which you do not need awk at all, or
plain processing of a file by awk and redirecting the output, or
processing a file of input with awk while having a 2nd file being processed too?

Processing a file of input and redirecting the output to another file. How Would I put input file name and out put file name in awk script, not thru command line

I am not sure if I understand - the explanation seems so simple in regards to your former thread How to grep on unique id which has request and response on different lines?

Anyway, you use awk in a shell script the same way as you do that in a shell.
In your code like example, you used -f to give awk a script file. The last argument is always the file name of the file to be processed (for example data, logs...).

awk '{print $1}' infile > outfile
#or
awk '{print $1 >> outfile}' infile

I am not sure if this hits what you are looking for - else a bit more detailed explanation could help, or maybe another poster understands it, sorry.

Thanks, Assumes input file name is test.log on which my.awk script runs and it gives output to output.log

I can run this script by this command through command line

./my.awk test.log > output.log

How can I put this test.log and output.log in my.awk so that if I run below command it should work.

./my.awk
 
Cat my.awk
#!bin/awk -f
function(time){
}
{
action####
}
END{
print(""')
}

I see no easy way to do that, that is not awkward. Neither do I see a reason why this has to be done. What is the reason if I may ask? Why not just use a shell script that calls awk?

Maybe someone else has an idea how to do that the way you want it.