We help IT Professionals succeed at work.
Get Started

how to execute multiple search and replace regular expressions using against the same log files Perl?

Last Modified: 2012-05-11
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)(?!hardware-type)}{$1Undefined Hardware type\n}ms;

Here's the code I started but not completed..


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/test_logs";
         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.

Watch Question
This problem has been solved!
Unlock 2 Answers and 3 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE