Difference between revisions of "bash variable inside awk"

From thelinuxwiki
Jump to: navigation, search
(Created page with "taken from [http://stackoverflow.com/questions/19075671/how-to-use-shell-variables-in-an-awk-script How to use shell variables in an awk script] This is the best way to do it...")
 

Latest revision as of 01:44, 10 May 2017

taken from How to use shell variables in an awk script

This is the best way to do it. It uses the -v option: (P.S. use a space after -v or it will be less portable. E.g., awk -v var= not awk -vvar)

variable="line one\nline two"
awk -v var="$variable" 'BEGIN {print var}'
line one
line two