noviceuser has asked for the wisdom of the Perl Monks concerning the following question:
I am writing a script where if a pattern/string is found in my log file, it should print the complete line along side its line number.
ex: there is a string match "Error" at line no. 4 then it should print like below
4: compilation Error during initial build
Here is the code i have written as of now
my $log = "${PORT_LOG_DIR}/abc.log"; open(MY_LOG, $log) or die "Could not open file 'log' $!"; while (my $line = <MY_LOG>) { chomp ($line); if ($line =~ /Error compiling file|Error:/i) { . . } } close(MY_LOG);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: print complete line along side line number, when a pattern is matched in log file
by hippo (Archbishop) on Jun 23, 2023 at 08:34 UTC | |
by cavac (Prior) on Jun 26, 2023 at 08:51 UTC | |
|
Re: print complete line along side line number, when a pattern is matched in log file
by parv (Parson) on Jun 23, 2023 at 07:37 UTC |