Extract string from a file using PERL

Posted on 2009-04-24
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 ================================
Question by:Billu_m
    LVL 84

    Expert Comment

    sub function{
      local @ARGV=("file");
      /installation operation completed successfully/ and return 1 while <>;
    LVL 10

    Accepted Solution

    simple code

    if the file pass by parameter, change:

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


    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


    Author Comment

    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 "



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    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…
    I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
    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…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now