how to replace html line into a command line?

hi!

i'm trying to use sed for this, but i'm struggling a lot. i want to convert

<div class="middle" id="middle">Friday, 20 April 2012<br /> <span class="hex">728CB5</span> <br /></div>

into

fbsetroot -solid '#728CB5'

considering all information between 'id="middle">' and '<br /> <span' should be ignored or removed earlier (because it may vary), or only considering the information between '="hex">' and '</span>'

(that html line above were obtained from

wget http://www.chromatweet.com/index.html -O _.html && cat _.html | grep hex | grep middle

) (added some spaces on the url above because this forum is blocking urls in messages like this)

thanks in advance! :slight_smile:

---------- Post updated at 12:15 PM ---------- Previous update was at 10:26 AM ----------

this code is working, but if you know some way to make it simpler, be welcome suggesting

wget http://www.chromatweet.com/index.html -O _.html
cat _.html | grep hex | grep middle | sed -n -e 's/.*hex\"\(.*\)\/span.*/\1/p' | sed -e 's/>/fbsetroot -solid \x27#/' | sed -e 's/</\x27/' > _.sh
chmod +x _.sh && bash _.sh && rm _.sh _.html

Hi try:

wget http://www.chromatweet.com/index.html -O - 2>/dev/null | awk '/middle/{gsub(/<[^>]*>/,x);print "fbsetroot -solid \x27#" $NF "\x27"}'

Hi nitrofurano,

One way with perl:

$ perl -MLWP::Simple -e '
    if ( ( grep { m/middle/ && m/hex/ } split /\n/, get( q[http://www.chromatweet.com/index.html] ) )[0] =~ m/"hex">(\d+)</ ) { 
        system( q[fbsetroot], q[-solid], qq['#$1'] ) 
    }
'