?
Solved

Global text edit

Posted on 2004-09-16
11
Medium Priority
?
191 Views
Last Modified: 2010-03-05
Hi All

We have sometimes 100’s of web pages to edit on our server and would like a Perl script to do it if possible. The preset variables that I would like to be able to edit would be:

$FolderPath = "the/path/to/the/folder/to/edit";
$ExtentionToEdit = "htm";
$LookFor = "look for text like this and change it";
$Replace = "This is my new text for this file";

Thanxs!
0
Comment
Question by:blnukem
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 6

Expert Comment

by:holli
ID: 12074564
use File::Find;

$FolderPath = "the/path/to/the/folder/to/edit";
$ExtentionToEdit = "htm";
$LookFor = "look for text like this and change it";
$Replace = "This is my new text for this file";

find(\&wanted, $FolderPath);

sub wanted
{
      if ( $File::Find::name =~ /$ExtentionToEdit$/ && -f $File::Find::name )
      {
            system ("perl -ni.bak -e \"s/$LookFor/$Replace/; print;\" $File::Find::name\"");
      }
}
0
 

Author Comment

by:blnukem
ID: 12082574
holli

I get this error:

sh: -c: line 1: unexpected EOF while looking for matching `"'
sh: -c: line 2: syntax error: unexpected end of file

I would really like to accomplish this with the use of modules some of our serverdont have all modules installed.
0
 
LVL 6

Expert Comment

by:holli
ID: 12099728
you will have to add the shebang-line at the beginning of the script. like:

#!/usr/bin/perl

the line must point to the correct path of your perl interpreter.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:blnukem
ID: 12100095
I did

#!/usr/bin/perl

use File::Find;

$FolderPath = "/usr/local/etc/httpd/htdocs/test";
$ExtentionToEdit = "htm";
$LookFor = "Old Words";
$Replace = "New Words";

find(\&wanted, $FolderPath);

sub wanted {

     if ( $File::Find::name =~ /$ExtentionToEdit$/ && -f $File::Find::name ){
          system ("perl -ni.bak -e \"s/$LookFor/$Replace/; print;\" $File::Find::name\"");
     }
}
print "Content-type: text/html\n\n";
print "done";
0
 
LVL 6

Expert Comment

by:holli
ID: 12100274
and?
0
 

Author Comment

by:blnukem
ID: 12100278
I get this error:

sh: -c: line 1: unexpected EOF while looking for matching `"'
sh: -c: line 2: syntax error: unexpected end of file
0
 
LVL 6

Expert Comment

by:holli
ID: 12100945
you are still exexuting the script to the shell not through perl!

try typing

perl scriptname

at the command-line
0
 
LVL 6

Expert Comment

by:holli
ID: 12100968
what's the output of the following

#!/usr/bin/perl
@a = ("hello ", "from ", "perl ");
print "@a;

??
0
 

Author Comment

by:blnukem
ID: 12167370
hello from perl
0
 
LVL 6

Accepted Solution

by:
holli earned 2000 total points
ID: 12167766
replace
   system ("perl -ni.bak -e \"s/$LookFor/$Replace/; print;\" $File::Find::name\"");

with
   system ("perl -ni.bak -e \"s/$LookFor/$Replace/; print;\" $File::Find::name");
0
 

Author Comment

by:blnukem
ID: 12167819
Thanxs!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question