Using bash variables in awk

First you need to assign the variables with the -v option:
The option -v followed by var=value is an assignment to be done before (the awk program).

Example of use:
This example define a bash file, that look for any entry “address” into the squid’s access file.

$ cat > search
#!/bin/bash
awk -v address=”$1″ ‘$3 == address && $4 ~ /200/’ /var/log/squid/access.log

$ chmod +x search; sudo ./search 192.168.0.2

Using bash variables in awk

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s