Solved

Global text edit

Posted on 2004-09-16
11
188 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
  • 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 500 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to strip .csv from file name 9 84
Move Function in Perl Script 2 74
How to get all the API from website? 11 123
Perl script to delete older files 6 94
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…

713 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