areyouready344
asked on
how to execute multiple search and replace regular expressions using against the same log files Perl?
What's the best way to execute multiple search and replace regular expressions for a single exs.log file for formating using Perl?
For example, I have a log file call exs.log and would like to run the following two search and replace lines below against it. In reality, I have more than two search and replace lines but knowing how to do two search and replace lines would be good enough
$_ =~ s/(^\@.*?)\n(or\s+.*)/$1$2 /ms;
s{^(\@test.*?$os(?:\s*\([^ )]+\))?\s* \n)(?!hard ware-type) }{$1Undefi ned Hardware type\n}ms;
Here's the code I started but not completed..
#!/usr/bin/perl
use warnings;
use strict;
my @log_files = qw(esx.log esx.log2 esx.log3);
foreach (@log_files)
{
open 'Input_log','<',"/etc/log/ $_";
open 'Output_log','>>',"/home/t est_logs";
while(<Input_log>)
{
I'm at a lost from this point on... I'm not sure how to take the output of a log file for a search and replace and use it as an input_log to another search and replace line.
}
}
For example, I have a log file call exs.log and would like to run the following two search and replace lines below against it. In reality, I have more than two search and replace lines but knowing how to do two search and replace lines would be good enough
$_ =~ s/(^\@.*?)\n(or\s+.*)/$1$2
s{^(\@test.*?$os(?:\s*\([^
Here's the code I started but not completed..
#!/usr/bin/perl
use warnings;
use strict;
my @log_files = qw(esx.log esx.log2 esx.log3);
foreach (@log_files)
{
open 'Input_log','<',"/etc/log/
open 'Output_log','>>',"/home/t
while(<Input_log>)
{
I'm at a lost from this point on... I'm not sure how to take the output of a log file for a search and replace and use it as an input_log to another search and replace line.
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Also, you need to define $os for the above code to work.