help in find and replacing a string in a number of files

2004-04-01 Thread prabu
Hi,
 i am new to perl.I am in a problem,So please help me to get a solution
"I want to change texts in 172 files available at a directory
/pages(there are files also in a sub-directory),they all  are text files.
 There are also some text files,which I no need to change.I want one
single script to open all these files,match the particular
 string and replace them with new string.

I tried with a singel file,able to open that file,make changes ,but only
write in another file.I want to write the changes in same old file.


the string needed to find:




the string to be replaced is;


  
document.write("");
  
Can anyone help me in this,
With Thanks in advance,
prabu.


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.620 / Virus Database: 399 - Release Date: 3/11/2004




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: help in find and replacing a string in a number of files

2004-04-01 Thread Charles K. Clarkson
prabu <[EMAIL PROTECTED]> wrote:
: 
:  i am new to perl.I am in a problem,So please help me to 
: get a solution
: "I want to change texts in 172 files available at a directory
: /pages(there are files also in a sub-directory),they all  are 
: text files.
:  There are also some text files,which I no need to 
: change.I want one
: single script to open all these files,match the particular
:  string and replace them with new string.

Read the file 'perlrun' included in your perl distribution.
The section under the -i option gives examples of how to do this.

HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: help in find and replacing a string in a number of files

2004-04-02 Thread senthil prabu
Hi,
 I want to open all (.txt,.html,.js files) files in a particular directory and replace 
a text in all that files.
 What I done so far was a script to replace text in all files in the current directory.
 What I want was," When I run the script,it should ask for the path of a particular 
directory and also the
 types(all files of its type in that dir) of files to open.
 
 I wrote a script to change the directory to I specified through commandline.but again 
it lists only
 the files in current directory.
 Please help me in this issue,
 The code is
 
print "Enter a path name: ";
my $path=;
chdir($path);
 
my $file='';
my @files=<*.txt>;
 
foreach $file (@files){
{
inner loop for pattern matchinh
};
 
 
With Thanks inadvance,
Prabu.



Win an evening with the Indian cricket captain: Yahoo! India Promos.

RE: help in find and replacing a string in a number of files

2004-04-02 Thread Charles K. Clarkson
senthil prabu <[EMAIL PROTECTED]> wrote:

[Please post replies to the list and do not top post]

: 
: "Charles K. Clarkson" <[EMAIL PROTECTED]> wrote:
: : 
: : Read the file 'perlrun' included in your perl
: : distribution. The section under the -i option gives
: : examples of how to do this.
: 
: Thanks for the reply. Since I am new to perl, I don't
: know more about perl distribution.

From the command line type: perldoc perldoc


: Please help me to get into it or give some sample
: scripts.

You can:
- look for the 'perlrun' file at perldoc.com,
- Use local html files if you have an ActiveState
  install, or
- From the command line type: perldoc perlrun


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: help in find and replacing a string in a number of files

2004-04-02 Thread Jayakumar Rajagopal


-Original Message-
From: senthil prabu [mailto:[EMAIL PROTECTED]
Sent: Friday, April 02, 2004 12:55 AM
To: Charles K. Clarkson; [EMAIL PROTECTED]
Subject: RE: help in find and replacing a string in a number of files


Hi,
 I want to open all (.txt,.html,.js files) files in a particular directory and replace 
a text in all that files.
 What I done so far was a script to replace text in all files in the current directory.
 What I want was," When I run the script,it should ask for the path of a particular 
directory and also the
 types(all files of its type in that dir) of files to open.
 
 I wrote a script to change the directory to I specified through commandline.but again 
it lists only
 the files in current directory.
 Please help me in this issue,
 The code is
 
print "Enter a path name: ";
my $path=;
chdir($path);
 
my $file='';
my @files=<*.txt>;
 
foreach $file (@files){
{
inner loop for pattern matchinh
};
 
 
With Thanks inadvance,
Prabu.

Senthil,
   Try this in inner loop :
my @files = <*>;
if ( ! -d $file && $file =~ /\.txt/ )
{do replacement}
else  {  chdir($file) ; do recuresion that calls this function }

Jay

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>