How to pass shell variables in awk

How to pass shell variables in awk

#!/bin/sh

SCRIPTVAR1=`hostname`
SCRIPTVAR2=`date`

awk ‘{
printf(“These are external shell variables %s and %s
“,SOMEVAR,OTHERVAR);
}’ SOMEVAR=$SCRIPTVAR1 OTHERVAR=”$SCRIPTVAR2″ infile

Example :
awk ‘{ … }’ SOMEVAR=$SCRIPTVAR1 OTHERVAR=”$SCRIPTVAR2” infile