pass variable to awk from outside
* * * * * 2 votos
October 17th, 2006 mysurface Posted in Bash, Text Manipulation, awk | Hits: 7526 |
Many people uses awk in their shell script, but they need to pass variable to awk for manipulation, it is not difficult, bellow is a simple example.
awk 'END { print myval }' myval=`pwd` data.txt
This example is to show you, I successfully pass a value from outside, at the END of the manipulation, print me my value I pass in. You can specified any variable name, for this case i uses “myval”.
If you define your awk rules in a file, you can do that as bellow to pass in variables.
awk -f bandwidth.awk measurement="kbps" proto="tcp" pcap.tr
Live Chat!









September 14th, 2008 at 5:11 am
thanks.