#Extract Image URLs and WGet Them to a New Server#
This was a fun problem. I needed to move all the images referenced in a CSS file to another server. I didn't want to just grab all the image files as there were a bunch I didn't need. Here is how I went about it. I am sure you could do it in one step but doing it this way gives you a chance to check for errors.
First you may want to use wget http://otherserver/the_css.css
to pull the CSS file on to the target server if it is still on the old server as it was in my case.
-
User grep to extract the URLs from the css file into another file. (You may need to adjust the regular expression if you have funny characters in your file names) Note the use of the
-o
flag that tells grep to only print out that part of the line that matches the expression rather than the entire line.grep -o '\/path\/to\/files\/[a-zA-Z0-9/.:_-]*' the_css.css > images.txt