Page 1 of 1

How to pass shell variables in awk ?

Posted: Fri Aug 12, 2016 7:17 pm
by triapthisuresh
how to pass shell variables in awk?

Re: How to pass shell variables in awk ?

Posted: Fri Aug 12, 2016 7:18 pm
by amit.g512
You can do in this way

#!/bin/sh

SCRIPTVAR1=`hostname`
SCRIPTVAR2=`date`

awk '{
printf("These are external shell variables %s and %s\n",SOMEVAR,OTHERVAR);
}' SOMEVAR=$SCRIPTVAR1 OTHERVAR="$SCRIPTVAR2" infile