How can I download png images from an xml feed that looks the following way?

<ListBucketResult xmlns="http://url1.com">

I was taking a look at this question on here about the same topic, except that I don't need to rename them, just download them.

Being new to shell scripts, I'm not quite sure how to do this (although I can definitely do this in 2 minutes in objective-c).

I have tried creating the following script and running bash myscript.sh

for u in $(curl -s "$URL" |
           grep png | 
           sed -E 's/.*<ImageStuff>(.+)<\/ImageStuff>/\1/'); do
    curl -s "$u" -o $i.png
    (( i++ ))

But nothing happens. It just prints another line without errors.

1 Answer 1


After curl http://theurlwiththexml.com:

sed -n 's,.*<ImageStuff>\(.*\.png\)<.*,\1,p'|xargs -I, curl http://url1.com/, -o ,

sed -n disables printing, \( and \) are a portable way to specify groups, and p prints the pattern space. xargs -I specifies a replacement string and curl -o specifies an output file.

Or using xmlstarlet, parallel, and wget:

xml sel -t -v //ImageStuff|parallel wget http://url1.com/{}

sel is an abbreviation for select, -t -v uses the value template, and //ImageStuff is an XPath expression that matches all ImageStuff nodes.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .