?
Solved

Finding errored files

Posted on 2003-03-09
7
Medium Priority
?
173 Views
Last Modified: 2010-03-05
I have a log file that contains errors and the name of the files that caused the errors on separate lines.   I would like to create a file that contains the name of all the files that caused an error. I.e. the below file will output the "h:/index/names/020202.xml" and "h:/index/names/020205.xml" in new file.




Processing file h:/index/names/020202.xml
Processing file step 1
Processing file step 2
Processing file step 3
OBDC:: error file cannot be put in database.
Processing file h:/index/names/020203.xml
Processing file step 1
Processing file step 2
Processing file step 3
Processing xml file successful.
Processing file h:/index/names/020204.xml
Processing file step 1
Processing file step 2
Processing file step 3
Processing xml file successful.
Processing file h:/index/names/020205.xml
Processing file step 1
Processing file step 2
Processing file step 3
OBDC:: error file cannot be put in database.
0
Comment
Question by:2xdafun
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 26

Expert Comment

by:wilcoxon
ID: 8100665
This should do it:

open IN, 'original.log' or die "could not open
original.log: $!";
open OUT, '>new.log' or die "could not write new.log: $!";
my $last = '';
while (<IN>) {
    chomp;
    if (/^Processing file ([\w:\/]+)\s*$/) {
        $last = $1;
    } elsif ($_ eq 'Processing xml file successful.') {
        $last = '';
    } elsif (/error/) {
        print OUT $last, "\n";
    }
}
close IN;
close OUT;
0
 

Author Comment

by:2xdafun
ID: 8106774
I got the below error message:

[/private/tmp] root# ./script.txt
2003-03-10 18:14:43.773 open[14871] No such file: /private/tmp/IN,
2003-03-10 18:14:43.895 open[14872] No such file: /private/tmp/OUT,
./script.txt: my: command not found
./script.txt: line 5: syntax error near unexpected token `(<IN>)'
./script.txt: line 5: `while (<IN>) {'
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 8110108
----------------------------------X8------------
#!/usr/bin/perl

open IN, 'original.log' or die "could not open
original.log: $!";
open OUT, '>new.log' or die "could not write new.log: $!";
my $last = '';
while (<IN>) {
   chomp;
   if (/^Processing file ([\w:\/]+)\s*$/) {
       $last = $1;
   } elsif ($_ eq 'Processing xml file successful.') {
       $last = '';
   } elsif (/error/) {
       print OUT $last, "\n";
   }
}
close IN;
close OUT;

----------------------------------X8------------

You need to do the following:

1. Add the #! first line so that it runs as a perl script.
2. Ensure that the file names are changed correctly.


Hope that helps:)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 22

Expert Comment

by:pjedmond
ID: 8110109
Points for this go to wilcoxon:)
0
 
LVL 26

Expert Comment

by:wilcoxon
ID: 8111667
Thanks pjedmond.  I was in a hurry when originally answering and forgot my usual comments to that effect (then, for some reason, I never got notified that 2xdafun added a comment yesterday).
0
 

Author Comment

by:2xdafun
ID: 8113923
Thanks that helped a little.  The file new.log supplies we with two empty lines.
0
 
LVL 26

Accepted Solution

by:
wilcoxon earned 200 total points
ID: 8114274
It looks like the regex line I gave you is incomplete.  Change this line:

if (/^Processing file ([\w:\/]+)\s*$/) {

To this:

if (/^Processing file ([\w:\/\.\\]+)\s*$/) {

You might need to add something else to it as well.  That regex says that the filename is made of of letter characters and underscores (\w), colons (:), slashes (/), back-slashes (\), and periods (.).
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question