Hi,

I am trying to search for a line in a file, comment that line using a " * " and finally append the range of corresponding lines extracted from the same file. The corresponding extracted range of lines maybe present before or after the line (which is to be commented).

Below is my file Test.txt

   Data to be ignored 
   Data to be ignored

   PERFORM P5X98A-PGM-INITS. # This line needs to be commented with a *
   #Append a copy of the corresponding extracted range of lines here.
   Data to be ignored
   Data to be ignored

   P5X98A-PGM-INITS SECTION.
   data to be stored 1
   data to be stored 1
   P5X98A-PGM-INITS-EXIT. EXIT.

   P5X98A-ABC-LIMIT SECTION. 
   Data to be stored 2
   Data to be stored 2
   P5X98A-ABC-LIMIT-EXIT. EXIT

   Data to be ignored 
   Data to be ignored 

   PERFORM P5X98A-ABC-LIMIT.  # This line needs to be commented with a *
   #Append a copy of the corresponding extracted range of lines here.
   Data to be ignored 
   Data to be ignored

Below is my code.

my $j=0;
open FILE1, "+<Test.txt" or die "Cannot open Test.txt!";

while (<FILE1>) {

  if (/$secarr[$j]/../$exarr[$j]/) {


    next if /$secarr[$j]/ || /$exarr[$j]/;

    if(my $dummy =~  s/^$perform[$j]/* $perform[$j]/)
   {
    print FILE1 $_;
   }     

  }
 $j++;
}

Where @secarr & @exarr contains the start and end strings. And @perform array contains all the lines starting with PERFORM statements.

Thanks in advance,

Hi,
I believe there are alot of people that are willing to help if your question is clear enough.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.