How to pass shell variables in awk

0 Flares Facebook 0 Twitter 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×

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

Comments

comments

Leave a Reply

Your email address will not be published. Required fields are marked *