How to use a variable in an awk expression
Posted
by lugte098
on Stack Overflow
See other posts from Stack Overflow
or by lugte098
Published on 2010-04-08T10:24:36Z
Indexed on
2010/04/08
10:33 UTC
Read the original article
Hit count: 399
I'm trying to make this command:
sed bla bla filename | awk '{printf "%s %s_entry_%.3f %.3f %.3f %.3f",$1,$3,$4,$5,$6,$7}'
But the thing is, i want the %.3f part to be variable. So in one case it could be %.3f and in another it could be %.3f %.3f %.3f. So i'll just use a static one in my example code for clarity. So if i want 4 of these %.3f and put them in variable $values like so:
values="%.3f %.3f %.3f %.3f"
Then how can i put this string in the awk expression, without making awk to just put literally "${values}" in there. The following is my non-working-attempt:
sed bla bla filename | awk '{printf "%s %s_entry_${values}",$1,$3,$4,$5,$6,$7}'
© Stack Overflow or respective owner