Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Finding errored files

Posted on 2003-03-09
7
Medium Priority
?
177 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
  • 3
  • 2
  • 2
7 Comments
 
LVL 27

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
Industry Leaders: 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!

 
LVL 22

Expert Comment

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

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 27

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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

564 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