tags:

views:

17

answers:

1

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

A: 

It's possible to use sed to change the file in-place using the -i option.

For your use it's up to you if it's easier/better to create a new file with the changes from the old, then copy to the 2nd domain using scp (or something similar). Or it may be easier to copy the file first, then modify it once it's on the remote server (less management of new filenames this way).

Ryan P.
The html files are generated solely for this purpose, so modifying them in-place is my preferred option.
Phil
cat *.html | grep -oE [^\"]+userfiles[\/.*]*/[^\"]+ |sort|uniq | sed 's/\(.*\/\(.*\)\)/cp \"\/var\/www\/drupal\1\" \".\/\2\"/g' | sed 's/%20/ /g' >> move_images.sh bash move_images.sh sed -i 's/\/userfiles\/\([^\"\/]*\)/\1/g' *.html
Phil