Shell variable can be ported into awk command by using "-v" flag:
An important note here is that within the awk command, calling the var does not require the '$' sign.
If there are more than one shell variable to call, use -v again and put space in between:
This will print $1*$var and $var2.
|
#!/bin/bash var=100 awk -v var=$var '{print $1*var}' file.dat |
If there are more than one shell variable to call, use -v again and put space in between:
|
awk -v var=$var -v var2=$var2 '{print $1*var, var2}' file.dat |