Passing values out awk.

found that passing (input) values to awk, all work well. For example:
errpt | awk 'BEGIN { errore=0 }
substr($2,1,4) /'ParamData'/ {
....
} ' ParamData=`date +"%m%d"`

Now I wish to obtain (output) a value. Using this method is it possible to re-write ParamData, for example?

Thanks in advance for your kind cooperation.
Regards.

Giovanni

You can print the value in awk and read it into your script, e.g...

$ echo 1 | awk '{print $1 + p}' p=2 | read p
$ echo $p
3

Ygor,
Over the past week or so I have had to write a couple of awk scripts and have really begun to see how powerful it can be. However, awk is still a bit foreign to me, can you elaborate on this syntax for me? What confuses me is the fact that p=2 is outside of the ending quote for the awk peice. How is the value of 2 available to awk?

echo 1 | awk '{print $1 + p}' p=2 | read p

Ygor really a expert in awk!! I viewed his posts and I still need to learn from him/her.

I know that is one of method to set variable in awk.

And I know 3 methods to do that, maybe more than 3 ways then I may not know.
Method 1:
Variable was assigned after any actions, var cannot be read in BEGIN {} because action in BEGIN {} is started before reading the script.
awk '{print $0}' var=$1 filename

Method 2:
One variable with one -v, variable can be read in BEGIN{} and the script.
awk -v var1=$1 -v var2=$2 '{print $0}' filename

Method 3:
assign variable in the script body.