[H-GEN] Scripting guide

McBofh McBofh at jmcp.id.au
Thu May 25 04:14:27 EDT 2006


Jason Parker-Burlingham wrote:
> On 5/25/06, McBofh <McBofh at jmcp.id.au> wrote:
>> $ awk '/[0-9].*\.[0-9].*\.[0-9].*\.[0-9].*\./ {print $8,$13}' \
>>         /var/apache/logs/error_log
>> I'm using the metacharacter sequence [0-9] to match any sequence of
>> characters in the set {0,1,2,3,4,5,6,7,8,9}, ".*" to match any number
>> of characters, and "\." to match the period character.
> That regular expression is only matching by accident:  you're matching a
> digit, any number of any character, then a period, four times.  In
> particular, your first line of output is matching because [0-9].*\. is
> matching these four strings:
>  192.
>  168.
>  1.
>  20] /scratch/web/htdocs/favicon.
> What you want is:
>  awk '/([0-9]+\.)+[0-9]+/ {print $8,$13}' \
>  /var/log/apache/error.log.1
> I'm not sure if + is a GNU extension to awk, but [0-9][0-9]* will do in its
> place.  I think you'll find that this matches many more error.log entries.
....


Hi Jason,
yup, you're quite correct. Thanks for picking up on that.



cheers,
James






More information about the General mailing list