How to pass shell variables in awk ?

triapthisuresh
Posts: 133
Joined: Fri Aug 12, 2016 1:17 pm

How to pass shell variables in awk ?

Postby triapthisuresh » Fri Aug 12, 2016 7:17 pm

how to pass shell variables in awk?

amit.g512
Posts: 81
Joined: Fri Aug 12, 2016 6:55 pm

Re: How to pass shell variables in awk ?

Postby amit.g512 » Fri Aug 12, 2016 7:18 pm

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


Return to “Scripting”

Who is online

Users browsing this forum: No registered users and 2 guests