in reply to Scan Files - Match String
Hi deelinux,
Please use <code> tags for the sample input as well. Also, your code does not compile, I had to add use POSIX 'strftime'; and a missing semicolon.
Its not matching
When I run your code against your sample input, it appears to work for me, the output I get is:
/tmp/logs/test.log 2017-01-04 08:14:19,753 - 08:14:19,752 WARN /tmp/logs/test.log 2017-01-04 08:14:19,753 - 08:14:19,752 ERROR
Is this not what you were expecting?
Update 2: Never mind, I missed the fact that $match1 was commented out (due to the missing use strict;). The advice below still applies!
Please see How do I post a question effectively? (Update: And post a Short, Self-Contained, Correct Example. Code that complies cleanly and some more sample input and its expected output would be good, since I'm unclear on "What I want is the date anything in between and then on the ERROR or WARN")
if anyone can shed some light that would be good or an easier way
In general, you should Use strict and warnings, it helps prevent mistakes. Second, you don't need to make your regexes so complex, and you can split them into several regexes if it makes it easier to think about. For example, to match on the current date and then on "ERROR" or "WARN", you could just write if (/\Q$strftime/ && /ERROR|WARN/) ...
Update 3: See also my other reply for a fix to your problem.
Hope this helps,
-- Hauke D
|
|---|