#!/\\perl # use strict; use warnings; use CQPerlExt; use Getopt::Long; use Time::Local; use File::Basename; # Put the file name in a string variable # so we can use it both to open the file # and to refer to in an error message # if needed. my( $dataLine ); my( $fileName ); my( $success ); # Hard-code the name of the file we're going to read. # This is the script itself. $fileName = '/\\rat09awp\ccscripts\Islam\test.log'; my $start = 0; # Attempt to open the file. We create a file handle called "IN". # Open returns a true value if it succeeded, an undefined # value if it didn't succeed. $success = open( IN, "<$fileName" ); if ( $success ) { # We opened the file successfully. # We loop until we don't get any more data from the file. When the # file has been exhausted, the value of $dataLine is set to undefined. # So we simply test $dataLine to see if it is defined after we have # obtained another line from the file. while ( defined( $dataLine = ) ) { # while () { # print $_; # if ($_ =~ /Duplicate remedy_id:/) { if ($dataLine =~ /Duplicate remedy_id:/ ) { printf $dataLine; while($dataLine = ) { if($dataLine =~ /Duplicate ip_address:/) { printf $dataLine; last; } else { printf $dataLine; } } } } # We have read all the lines from the file. # Close the file. close( IN ); } else { # Opening failed. The error message is stored in a special Perl # variable, $!. The die() function prints an error message, then # causes Perl to quit. die( "Can't open file '$fileName' for reading: $!.\n" ); }