[H-GEN] Scripting guide

Jason Parker-Burlingham jasonp at panix.com
Thu May 25 03:37:31 EDT 2006


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.

Of course, the grep, awk, and regex (man 7 regex) pages are the best
places for information.

jason




More information about the General mailing list