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

About these ads

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

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 )

Connecting to %s

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

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: