Copy/publish images linked from the html files to another server and update the HTML files referenci

Posted by Phil on Stack Overflow See other posts from Stack Overflow or by Phil
Published on 2010-04-28T04:41:39Z Indexed on 2010/04/28 5:03 UTC
Read the original article Hit count: 169

Filed under:
|
|
|

I am publishing content from a Drupal CMS to static HTML pages on another domain, hosted on a second server. Building the HTML files was simple (using PHP/MySQL to write the files).

I have a list of images referenced in my HTML, all of which exist below the /userfiles/ directory.

cat *.html | grep -oE [^\'\"]+userfiles[\/.*]*/[^\'\"] | sort | uniq

Which produces a list of files

http://my.server.com/userfiles/Another%20User1.jpg
http://my.server.com/userfiles/image/image%201.jpg
...

My next step is to copy these images across to the second server and translate the tags in the html files.


I understand that sed is probably the tool I would need. E.g.:

sed 's/[^"]\+userfiles[\/image]\?\/\([^"]\+\)/\/images\/\1/g'

Should change http://my.server.com/userfiles/Another%20User1.jpg to /images/Another%20User1.jpg, but I cannot work out exactly how I would use the script. I.e. can I use it to update the files in place or do I need to juggle temporary files, etc. Then how can I ensure that the files are moved to the correct location on the second server

© Stack Overflow or respective owner

Related posts about sed

Related posts about bash