Monks:
Okay, I have spent the past 45 minutes coding this entry in the hopes that it serves a lesson to others. Make sure that your question is properly formatted lest you receive an immediate reprimand.
This will be a clarification of my first post wherein I
deleted my original entry. Those who provided insight, however, have my most heartfelt thanks even though it resulted in errors because I was on a Windows Machine
To start, I am working on a Windows XP machine with C:/PERL
being home to all of my data and scripts for the purposes of these exercises produces the following.
C:/PERL/dread.log (a simple text file)
Within dread.log are the following entries:
This has no importance
This really has no importance
This is just plain boring
This is really important
This is blah blah blah
This is important to someone else
This is very important to you"
This is blah blah blah
The specific phrases (patterns?) that I want to spot are
'This is really important' as well as 'This is very important to you'
My goal is to create a script that I can execute against this log, or several logs, to look for specific phrases/patterns.
When these patterns are spotted, I would like them to be dumped to another file, say
C:/PERL/warnings.txt
I think that the poor man's logic behind this would be.
a. open the dread.log file
b. search the dread.log file for specific phrases/patterns
c. write out a new log file called C:/PERL/warnings.txt
I know that on Linux it would be a matter of EGREP, however,
since I am on a Windows machine I am going to have to accomplish this through PERL code alone.
I am not necessarily looking for the answer, as
this would defeat the purpose of using this as a learning opportunity, however, at the moment I am definitely running in lost circles.
Regards,
Doc Wally
# Okay, here is what a part of my log file looks like :
#:
#=~= PuTTY log 2008.07.01 12:18:34 :
#login as: BOO:
#bobthePC@10.105.102.62's password::
#"This is really important"
#"This is very important to you"
#"This is also important"
#CRON: 2008/06/26 04:35:00 [0] Another backup/restore operation is already running.
#CRON: 2008/06/26 04:40:00 [0] Another backup/restore operation is already running.
#CRON: 2008/06/26 04:45:00 [0] Another backup/restore operation is already running.
#CRON: 2008/06/26 04:50:00 [0] Another backup/restore operation is already running.
#CRON: 2008/06/26 04:55:00 [0] Another backup/restore operation is already running.
#--further down the log file, I may have an entry that says
#CRON: 2008/06/30 05:30:00
1 Device error - I0302 (example)
#
#
#now here is a slight modification of the script that I got from the Waldner earlier
use strict; use warnings;
# okay, I get that part
open ERROR, "dread.log" or die "Can't open input file";
# open the log file, or die - a bit extreme?
open OUT, ">warnings.txt" or die "Can't open output file";
# put your results in a file called warnings.txt
while (<ERROR>)
{
print OUT if /^("This is really important"|"This is very important to you"|"This is also important")$/;
}
# Problem is, if the text in the original log file is not in quotes, so the warnings.txt file output is
# simply
#"This is really important"
#"This is very important to you"
#"This is also important"
#
# I understand that this has to do with getting the regexes right - arggg, any breadcrumbs?
close ERROR;
close OUT;
AHA!!!
while (<ERROR>)
{
print OUT if (/This is really important/ | /restore operation is already running/ | /bobthePC/ | /This is also important/);
The phrases that are between the "/" will be spit out to the export file in the order that they appear in the log itself - so long as the actual data itself does not contain a "/" I should be fine. Of course, there is a way to contain this to permit for the "/" to be used, however, that is for tomorrow. Now I need a drink.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.