Solved

Global text edit

Posted on 2004-09-16
11
184 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
 

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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

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…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now