sranaghan has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I need to parse a log file that I will be using a UNC path for. It is a log file say on a Windows system. I need to just parse the log for a string called lets say "Error: This is an error" and I need to pump out the occurences of this error to a separate file. They key is I need it to pick up where the last error was found. In other words not to start reparsing the file from the beginning..thank you very much.... One further update....sorry folks....#####NEW POST####### Hi, I am trying to create some code that can trap errors and put them out to an external file. This code needs to be able to go out and look at the timestamp of an error and then from there determine if this error has been seen already and if it has ignore it otherwise add it to this external file and if it is a new alert to email someone (have the email code I think). If it finds an error basically it searches for an error with an older timestamp. basically I want to trap errors in a log and output them to the file as a way of monitoring and metrics.....Thanks for your help..

Replies are listed 'Best First'.
Re: File parsing
by almut (Canon) on Jun 04, 2009 at 21:15 UTC
    The key is I need it to pick up where the last error was found.

    You could obtain the file position of the last error via tell, store it somewhere, and then seek to that same position before continuing with parsing... (if I've understood the problem correctly, that is)

Re: File parsing
by targetsmart (Curate) on Jun 05, 2009 at 06:27 UTC
    I think 'grep' utility can help you to pump out occurrences of the error to a separate file.
    there is grep for windows available.
    Store the line number, when you are about to start checking at the same line where you left.(grep doesn't give this feature to start searching from a particular line number, so almut solution is best fit)

    Vivek
    -- In accordance with the prarabdha of each, the One whose function it is to ordain makes each to act. What will not happen will never happen, whatever effort one may put forth. And what will happen will not fail to happen, however much one may seek to prevent it. This is certain. The part of wisdom therefore is to stay quiet.
Re: File parsing
by stinkingpig (Sexton) on Jun 08, 2009 at 20:14 UTC