[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Extract string from a file using PERL

Posted on 2009-04-24
3
Medium Priority
?
978 Views
Last Modified: 2012-05-06
HI experts,

I have a content of a logfile as follows (below), I need to open a file and search for a string (using PERL)"Installation operation completed successfully"
string from this if this string is found i need to retrn 1 from the perl function.

can somebody help me in how can i approach this , can anybody send me the pseudo or link to  the similar script.

=== Logging stopped: 4/20/2009  23:02:18 =======================================
MSI (s) (18:78): Note: 1: 1707
MSI (s) (18:78): Product: XI R2 Service Pack 6 -- Installation operation completed successfully.
MSI (s) (18:78): Cleaning up uninstalled install packages, if any exist
MSI (s) (18:78): MainEngineThread is returning 0
MSI (s) (18:30): Destroying RemoteAPI object.
MSI (s) (18:08): Custom Action Manager thread ending.
MSI (c) (30:D0): Decrementing counter to disable shutdown. If counter >= 0, shutdown will be denied.  Counter after decrement: -1
MSI (c) (30:D0): MainEngineThread is returning 0
=== Verbose logging stopped: 4/20/2009  23:02:18 ================================
0
Comment
Question by:Billu_m
3 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 24223578
sub function{
  local @ARGV=("file");
  /installation operation completed successfully/ and return 1 while <>;
}
0
 
LVL 10

Accepted Solution

by:
oleber earned 2000 total points
ID: 24228516
simple code

if the file pass by parameter, change:

local @ARGV=("file_path.log");

to

local @ARGV= @_;
sub function {
    local @ARGV=("file_path.log");
    while ( my $line = <> ) {
        if ( $line =~/installation operation completed successfully/ ) {
            return 1 ;
        }
    }
    return 0;
}

Open in new window

0
 

Author Comment

by:Billu_m
ID: 24268536
HI oleber,

the code snippet works fine for "ANSI  Text documnet " , but not for " Unicode text document "

please let me know how to make it work for "Unicode text document "

Thanks
Billu_m


0

Featured Post

Technology Partners: 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

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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

864 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