pass variable to awk from outside

October 17th, 2006 mysurface Posted in awk, Bash, Text Manipulation | Hits: 28259 | 2 Comments »

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

2 Responses to “pass variable to awk from outside”

  1. thanks.

  2. Dalila Niemeier Says:

    i had love to check out the video of the tire appearing rolled to your dwelling…

Leave a Reply