Tag Archives: awk

shell expansion within awk

Say you have a loop in a shell script and want to expand a given variable within an embedded awk statement, this is how:

awk 'BEGIN { FS = "'${i}'" } do some more awking'
In this case $i is my shell variable, and I want to use it as a field separator.

It is just that easy, an extra ‘ to escape awk for a moment and expand $i!