Author: gnuhpc
Source: http://www.cnblogs.com/gnuhpc/
I. "'$ var '"
In this way, you do not need to change the habit of using the awk program. It is a common method used by foreigners. For example:
Var = "test" awk 'in in {print "'$ var '"}'
In this way, it is actually a constant that is changed from double brackets to single brackets and passed to awk.
If var contains spaces, shell should use the following as a grid character to avoid spaces:
Var = "this is a test" awk 'in in {print "'" $ Var "'"}'
Ii. '"$ Var "'
This method is similar to the previous one. If the variable contains spaces, it becomes '"$ Var" "' more reliable.
3. Change ''of the awk program to" "and use" $ Var"
For example, $ Var = "this is a test" awk "begin {print" $ Var "}" this is because $ is a special character in, in '', $ is a common character.
Iv. Export variable, in the form of Environ ["Var,
For example: $ Var = "this is a test"; export $ varawk 'in in {print environ ["Var"]} 'V: Of course, you can also use the-V Option
For example, $ Var = "this is a test" awk-vnvar = "$ Var" '{print nvar }'
In this way, the system variables are defined as awk variables.
Author: gnuhpc
Source: http://www.cnblogs.com/gnuhpc/