Forum Moderators: phranque

Message Too Old, No Replies

Command prompt problem

         

Wassercrats

2:21 am on Jul 25, 2005 (gmt 0)

10+ Year Member



I wanted to do a search and replace at the command line, but it didn't work, even though the same regular expression worked in my cgi-bin. Could somebody tell me why the substitution in the first script doesn't replace anything in the file, while the one in the second script does?

----------------------
Script 1 (doesn't work)
----------------------

system ('cd [full Unix path to the directory http://www.example.com/documents/BackgroundNotes/TEST/ goes here];find * -name \'1831pf.shtml\' ¦ xargs perl -pi -e "s/\<body\>.*\<\!\-\-\#include virtual\=\"\/cgi\-bin\/Banner\_BackgroundNotes\.pl\" \-\-\>\<br\>/\<body style \= \"margin\-top\: 1px\; padding\-top\: 1px\;\"\>\n\n\<p style \= \"text\-align\: center\; margin\-top\: 1px\; padding\-top\: 1px\;\"\>\n\<a href \= \"http\:\/\/www\.example\.org\"\>\n\<img style \= \"margin\-bottom\: 20px\; border\: none\;\" src \= \"http\:\/\/www\.example\.com\/images\/Banner\_BackgroundNotes\.gif\"\>\n\<\/a\>\n\<\/p\>\n\n\<br\>/s;"');

----------------------
Script 2 (works)
----------------------

$Direc = [full Unix path to the file http://www.example.com/documents/BackgroundNotes/TEST/1831pf.shtml goes here]";

open(IN, $Direc);
@file = <IN>;
close IN;

$Webpage = join ("", @file);

$Webpage =~ s/\<body\>.*\<\!\-\-\#include virtual\=\"\/cgi\-bin\/Banner_BackgroundNotes\.pl\" \-\-\>\<br\>/\<body style = \"margin\-top: 1px\; padding\-top: 1px\;\"\>\n\n\<p style = \"text\-align: center\; margin\-top: 1px\; padding\-top: 1px\;\"\>\n\<a href = \"http:\/\/www\.example\.org\"\>\n\<img style = \"margin\-bottom: 20px\; border: none\;\" src = \"http:\/\/www\.example\.com\/images\/Banner_BackgroundNotes\.gif\"\>\n\<\/a\>\n\<\/p\>\n\n\<br\>/s;

open(LOG, ">$Direc");
print LOG "$Webpage";
close(LOG);

-----------------------

The first script worked only when I shortened the regex to just replace the word "head" with a different word, but if the long regex works in the second script, I don't see why it won't work in the first.

[edited by: jdMorgan at 2:31 am (utc) on July 25, 2005]
[edit reason] No URLs, please. See Terms of Service. [/edit]