bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Passing variables to awk


From: Andreas Schwab
Subject: Re: Passing variables to awk
Date: Thu, 01 Nov 2007 12:05:30 +0100
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.1 (gnu/linux)

TimtheEagle <tim.cheyne@safecom.co.nz> writes:

This is actually all unrelated to bash.

> + awk -v 'var1=Framed-IP-Address = 10\.6\.6\.' '/*** Received from
> 10.242.252.20 port 1645 ..../{ last_acct_status = NR; as = $0 }/Code:      

`*' and `.' are special in regexps, you need to quote them to match them
as literals.

> Access-Accept/ && last_acct_status + 1 == NR {last_user_name = NR; print
> NR-1 as; print NR $0 }/$var1/ && last_acct_status + 10 == NR { print NR $0

/.../ is the syntax for a literal regexp.  To match against a variable
use `$0 ~ var1' (awk does not use $ to refer to variables).

> }' /tmp/theout
> awk: warning: escape sequence `\.' treated as plain `.'

The value is parsed as a string.  To include a backslash in a string
write it as \\.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




reply via email to

[Prev in Thread] Current Thread [Next in Thread]