Passing a shell script variable into an AWK command
The correct way to do this is using AWK's variable passing feature. Also, you probably only need to set OFS
once, so you should do it in the BEGIN
clause.
awk -F $'\xE7' -v awkvar="$shellvar" 'BEGIN {OFS ="¬"} { $3 = sprintf("%010s". $3) ; print $0, awkvar }' input file > outputfile
You could also use -v
to set OFS
:
awk -F $'\xE7' -v awkvar="$shellvar" -v OFS ="¬" '{ $3 = sprintf("%010s". $3) ; print $0, awkvar }' input file > outputfile
I just added the variable to the print
statement since I didn't know exactly how you wanted to use it.
awk has ENVIRON
array for accessing environment:
$ FOO=bar awk 'BEGIN{print ENVIRON["FOO"]}'
bar