Forum Moderators: bakedjake
I am not at all smart about regex and even after
reading websites devoted to regex tutorials, still
don't have a clue, too old (55) and unix dumb.
As it stands now I have thumbnails that just show
up on my pages because they are in the same directory as the html files, and I have a hard link to the full
sized pictures like such:
[boo.com...]
I need that path changed to
[boo.com...]
if I could use my old fashioned wildcard method
I would know how to make this work, but I use
Dreamweaver MX 2004 and it wont take the old *
as a wildcard, it wants to use regex for it's
search and replace. Also some images use .jpg others
use .JPG
I have tried to use .*\.jpg as my wild card but it
only adds the pics/ to the path and does not include
the image file name when it is processed. Any help
will be much appreciated.
Mike
perl -pi~ -e 's/test/replaced/' file
or in your case:
perl -pi~ -e 's/http:\/\/www.boo.com\/someimage.jpg/http:\/\/www.boo.com\/pics\/someimage.jpg/' index.html
I've tested it with a test file of my own, and it works...
You can even do multiple files (ie, *.html)
The only problem is that it won't dynamically replace the image names... So, you have to do them all manually... (ie: image1.jpg, image2.jpg) for each image you want moved.
As I was typing this, I came up with a quick script that'll do that for you...
Here's what you need to do:
change to the directory where you want your html files replaced.
cd /home/www/webroot vi replace.sh add the following into that file (Modify anything that you need to!)
#!/bin/sh
PICDIR="pics"
cd $PICDIR
list=`ls *.jpg`
cd ..
for i in $list
do
perl -pi~ -e 's/http:\/\/www.boo.com\/'$i'/http:\/\/www.boo.com\/'$PICDIR'\/'$i'/' *.html
done
move the existing images to your destination directory (ie: /home/www/webroot/pics) -- Make sure the directory exists first!
mkdir pics mv *.jpg pics now execute the script:
sh replace.sh This script assumes a few things:
change the "PICDIR" variable to be where you want your pictures to end up
I'm also assuming that you're going to run this script from where your pictures used to be.
I'm also assuming it's only .html files you want to modify.
so, my test setup looked like this:
where my pictures were:
/home/www/webroot /home/www/webroot/pics /home/www/webroot /home/www/webroot If there's anything I've missed, please let me know! I'd be happy to help out if it doesn't go as planned. :)
I hope that helps, and I hope it works out for you!
-MM