in reply to Re: Find & Replace
in thread Find & Replace

Hello

Thanks for the replies.

The content will be in file and I need to replace commas in first and last line only...

Thanks & Regards

Sridhar

Replies are listed 'Best First'.
Re^3: Find & Replace
by McDarren (Abbot) on Aug 10, 2006 at 15:08 UTC
    Well, if the file is not too big, a simple (but slightly convoluted) way to do that would be to read all the lines into an array, edit the first and last elements of the array, and then write the file back out again. Like so:
    open IN, "<", "file.txt" or die "Cannot open file.txt for reading:$!\n +"; my @lines = <IN>; $lines[0] =~ s/,+$/,/; $lines[-1] =~ s/,+$/,/; open OUT, ">", "file.txt" or die "Cannot open file.txt for writing:$!\ +n"; print OUT for @lines; close OUT;
      Thanks alot for the replies

      I got the solution


      Sridhar
      Hello The script is working fine thanks for the script. Any idea
      if the file is big how to achieve this task


      Thanks in advance Sridhar
      Hello


      If the file is big is there way to do this task...thanks again for your help
      Sridhar