Hello,

I'm trying to dispatch some contents from an apache log depending on a regexp and i have a problem. It seems strings which don't match my regexp goes in the matched area ...

example command-line:
$ cat access_log | perl -pe 'if (s/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3 +}).*"(GET|POST|HEAD) (.*?) HTTP\/.*$/$1,$3/) { print } else { print S +TDERR }' 2>out.err > out.csv

results in STDIN
[...] 72.30.161.243,/ 72.30.161.243,/ 125.224.206.168 - - [04/Oct/2009:00:13:42 +0200] "-" 408 - "-" "-" 125.224.206.168 - - [04/Oct/2009:00:13:42 +0200] "-" 408 - 125.224.206.168 - - [04/Oct/2009:00:13:47 +0200] "CONNECT 203.188.201. +253:25 HTTP/1.1" 404 516 "-" "-" 125.224.206.168 - - [04/Oct/2009:00:13:47 +0200] "CONNECT 203.188.201. +253:25 HTTP/1.1" 404 516 96.243.255.188,//phpMyAdmin/ [...]

STDERR has only valid contents (not matching regexp)

corresponding part of the source file:
72.30.161.243 - - [03/Oct/2009:17:21:43 +0200] "GET / HTTP/1.0" 404 51 +6 "-" "Mozilla/5.0 (compatible; Yahoo! Slurp/3.0; http://help.yahoo.c +o m/help/us/ysearch/slurp)" 72.30.161.243 - - [03/Oct/2009:17:21:43 +0200] "GET / HTTP/1.0" 404 51 +6 125.224.206.168 - - [04/Oct/2009:00:13:42 +0200] "-" 408 - "-" "-" 125.224.206.168 - - [04/Oct/2009:00:13:42 +0200] "-" 408 - 125.224.206.168 - - [04/Oct/2009:00:13:47 +0200] "CONNECT 203.188.201. +253:25 HTTP/1.1" 404 516 "-" "-" 125.224.206.168 - - [04/Oct/2009:00:13:47 +0200] "CONNECT 203.188.201. +253:25 HTTP/1.1" 404 516 96.243.255.188 - - [04/Oct/2009:00:26:17 +0200] "GET //phpMyAdmin/ HTT +P/1.1" 404 516 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)" 96.243.255.188 - - [04/Oct/2009:00:26:17 +0200] "GET //phpMyAdmin/ HTT +P/1.1" 404 516

Has someone encounters a similar bug ? or is it my regexp ? seems hard to believe that it matched the CONNECT line ...
Normally, out.csv must contains only csv lines.

thanks
Best regards

In reply to regexp matching bad stuff ... by raiten

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.