Replace string in existing file
From: Rich (dfwtp_at_bee.net)
Date: 02/19/04
- Next message: toylet: "references"
- Previous message: Kona: "Scripts to audit MS SQL Server"
- Next in thread: toylet: "Re: Replace string in existing file"
- Reply: toylet: "Re: Replace string in existing file"
- Reply: Joe Smith: "Re: Replace string in existing file"
- Reply: Rich: "Re: Replace string in existing file"
- Reply: Rich: "Re: Replace string in existing file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 18 Feb 2004 19:16:13 -0800
I am trying to replace the word "test" in a file with the word
"Change" without creating a new file using the following code:
#! /usr/bin/perl -w
open (IN, "+</path/to/file/test.html");
while (<IN>){
s/test/Change/;
print IN;
}
close IN;
The orignal file contains:
test 1
test 2
test 3
and my results are:
test 1
test 2
test 3
test 1
Change 1
test 3
Change 3
I am looking for the results to be:
Change 1
Change 2
Change 3
and that is what I get if I output the print to a new file or to
<STDOUT>.
What am I doing wrong? Any help would be much appreciated.
Thanks in advance
- Next message: toylet: "references"
- Previous message: Kona: "Scripts to audit MS SQL Server"
- Next in thread: toylet: "Re: Replace string in existing file"
- Reply: toylet: "Re: Replace string in existing file"
- Reply: Joe Smith: "Re: Replace string in existing file"
- Reply: Rich: "Re: Replace string in existing file"
- Reply: Rich: "Re: Replace string in existing file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]