Inserting variables within my awk statement?

Up vote 0 down vote favorite share g+ share fb share tw.

Here is a snippet of my awk statement..I'm trying to insert these 2 variables in the statement but they are not getting evaluated. Can someone point me in the right direction? ZONE=`date "+%Z %Y"` DAY=`date "+%a"` awk '{if (NR Protect the shell variables from awk by enclosing them with "'" (i.e.

Double quote - single quote - double quote). Awk '{print "'"$VAR1"'", "'"$VAR2"'"}' input_file bash awk link|improve this question edited 2 days ago asked 2 days agoJim112.

You can use -v option: ZONE=`date "+%Z %Y"` DAY=`date "+%a"` awk -vzone="$ZONE" -vday="$DAY" 'BEGIN { print zone, day }.

1 This most often also makes the awk script itself much cleaner than relying on the shell variables being expanded within the script. Also, this will also work in case where the awk script is provided as a separate file (awk -f scripfile. Awk).

– Juha Laiho 2 days ago.

Those variables won't be expanded where they're enclosed in single quotes. Consider using double quotes for your outermost quotes and escaped double quotes inside your awk expression. I'm only guessing here, though, as you do not appear to have included the actual command you used where your variables have been embedded, but aren't being evaluated.

In the future, or if this answer doesn't help, consider including the command you use as well as its output and an explanation of what you expected to happen. This way, it'll be much easier to figure out what you mean.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions