Web Hosting Talk







View Full Version : Egrep ?/Perl code to make massive changes server-wide


BooBoo
03-07-2003, 06:42 PM
I can format a egrep to locate html files that have a certain line in it. However, the egrep is not working like I would like it to. The command is:

egrep -r -l -i "cp-app.cgi\?pg=ste_chkout_proc" /home/sites/*/web/*.htm* > proddisp.txt

It grabs all the html files at the web level, but will not go down further than that. I know on a couple of domains, I have subdirectories that definitely have that html code that I need to change. For example, egrep -l -i -r "cp-app.cgi\?secure=Y&pg=ste_chkout_proc" /home/sites/*/web/links/*.htm* > proddisp.txt

will find all files at this level.

After I get that working, I want to use this perlscript to make the changes:

#!/usr/bin/perl
# This may F*up your server, it's not my fault.
# Check it first on something you don't care about.
# I did not try it, I just coded it on the fly.


$text_file_name = "filename_above_with_all_your_paths_and_filenames";


open (DATA, "$textfile");
@data = <DATA>;
close DATA;


foreach $record(@data) {


$filename = $record;
open (FILE, "$filename");
@file = <FILE>;
close FILE;


@file =~ s/http://www.domainname.com/ccp5/cgi-bin/cp-app.cgi?&pg=ste_chkout_proc/https://www.domainnamecom/ccp5/cgi-bin/cp-app.cgi?secure=Y&pg=ste_chkout_proc/g;


open (FILE, ">$filename");
print FILE "@file";
close (FILE);


}


However, I do not think that this will work due to the / in it. How can I accomplish this?

I got the perl code from the Sun site from GregD. Thanks Greg!

CmptrWz
03-07-2003, 08:49 PM
I know nothing about egrep beyond the little data I just read about it from egrep --help. Here is my take on your egrep issue:

The *.htm* is screwing up the recursive parameter.

You might want to modify your perl script to filter out files that aren't .htm or .html files, which is the only thing I can think of right now.

BooBoo
03-07-2003, 09:05 PM
that did it! I got the script figured out.

CmptrWz
03-07-2003, 09:52 PM
Logic prevails again :D