Mezgani blog

July 16, 2009

Using bash variables in awk

Filed under: bash — Tags: — Ali MEZGANI @ 12:55 pm

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

Theme: Silver is the New Black. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.