troubleshooting Question

search/replace suppl with $suppl

Avatar of GessWurker
GessWurker asked on
Perl
8 Comments1 Solution256 ViewsLast Modified:
I need to search for Suppl or suppl in the line starting with <IS and ending with <END> and change to $suppl.

   s"(<IS\s*>)(.+)(<END>)"    

Input: <IS > 1 Suppl 2 <END>
Output: <IS > 1 $Suppl 2 <END>

Input: <IS > suppl 4 <END>
Output: <IS > $suppl 4 <END>


Will add new search/replace to code snip below:
$/="<END>";
while( <> ){
    $flag='';
#version 4: not case-sensitive
   s/(<DC\s*>|<LA\s*>)(.+?)(<END>)/
       local $_=$2;
       my %seen;
       my @seen;
       {
           s"[\r\n]""g;
           @seen=grep{!$seen{$_}++}
                 map{$map{lc $_}||($flag=' #unknown',$_)[1]}
                 m"(\w[^;]+\w)"g;
       }
       $1.join(";",@seen).$3.$flag
      /es;
   s"(<DD\s*>)(.+)(<END>)"
       $flag = '# unknown date format';
       if( $var = (split(':',ParseDate($2)))[0] ){
         $var =~ s/(\d{4})(\d{2})(\d{2})\d+/ $2\/$3\/$1 /;
         $flag = '';
       }
        $1.($var||$2).$3.$flag;
   "es;
   print (OUTPUTFILE);
}
close(OUTPUTFILE);

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros