Avatar of dfn48

asked on 

Replace text in a file

I wrote a program using Perl to find and replace a text within a file.

The text that needs to be replaced in the file is 'sql7.0.1' with 'sqls715'.

When I execute my program I get an error message:

can't /tmp/odbc.ini_old : A file or directory in the path name does not exist. I check the path and the path is correct. My OS is AIX.

Here is my code:


use strict;
use warnings;

my $filename = '/tmp/odbc.ini.2014_old';
my $find=' sql7.0.1 ';
my $replace = ' sqls715  ';

   local @ARGV =($filename);
   local $^I ='.bac';
   while (<>) {
     if (s/$find/$replace/ig) {
 else {
print "Finished"

Open in new window


Avatar of undefined
Last Comment

8/22/2022 - Mon