[CS-FSLUG] Script for replacing a string in a html-document?

Robert W. robertwo at insightbb.com
Wed Oct 5 09:02:59 CDT 2005


At 06:20 AM 10/5/05, Jukka wrote:
> I hope you don't think I am too lazy (which I well may be.. :). I
> have 170 similar html-documents with links pointing to a wrong  
> directory which I'd like to correct, but not "by hand" (I have done  
> it once already and it was tough...). Could someone give me an  
> example-script which replaces string in a html-document? I go to look  
> something from the net while waiting your responses.

Try this Perl one-liner on one file to make sure it works correctly:
perl -np -e 's/olddir1\/olddir2/newdir1\/newdir2/g' onefile.html

When it works, then use this command to change all of the files:
perl -npi -e 's/olddir1\/olddir2/newdir1\/newdir2/g' *

-- 
Robert W.
robertwo at insightbb.com

Who of you by worrying can add a single
hour to his life? -- Matthew 6:27





More information about the Christiansource mailing list