Thanks John.
Those symbols made me crazy entirely.
As what you explained, some are metadata of regex, some are regular
characters, it's not clear to me, due to my poor knowledge on regex.
Yes I will learn them more.
thanks.
On 2018/7/13 星期五 AM 2:23, John W. Krahn wrote:
On Thu, 2018-07-12 at 19:35 +0800, Lauren C. wrote:
My web is powered by Apache and PHP,its access log seems as blow,
xx.xx.xx.xx - - [12/Jul/2018:19:29:43 +0800] "GET
/2018/07/06/antique-internet/ HTTP/1.1" 200 5489 "https://miscnote.ne
t/"
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"
A perl script for stat purpose of this log:
tail -f /var/log/apache2/access.log|perl -nle 'next unless m{^(\S+) -
-
\[(\S+).*\] \"GET (.*?/)\s+}; printf "%-20s%-40s%-40s\n",$1,$3,$2'
I was totally confused about it.
what does m{...} and its content stand for?
m{^
Start with the (^) beginning of line anchor, the following pattern must
match at the beginning of the line.
(\S+)
Match one or more non-whitespace characters and store the match in the
$1 variable. This matches the "xx.xx.xx.xx" portion of your string.
' - - \['
Match the literal characters SPACE HYPHEN SPACE HYPHEN SPACE LEFT-
BRACKET.
(\S+)
Match one or more non-whitespace characters and store the match in the
$2 variable. This matches the "12/Jul/2018:19:29:43" portion of your
string.
'.*\] \"GET'
Match zero or more non-newline characters followed by the literal
string '] "GET '.
(.*?/)
Match as few as possible non-newline characters followed by a '/'
character and store the match in the $3 variable. This matches the
"/2018/07/06/antique-internet/" portion of your string.
\s+}
And finally, match one or more whitespace characters so that the
previous non-greedy pattern will match correctly. The modifier is
redundant so it could simply be:
\s}
John
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/