How to parse a specifc value between html tags using sed?

Hi,

im trying to read a Temperature value from html code.

So far i have managed to reduce the whole html page down to this single line with the following sed command:

sed -n '/Temperature/p' $temp_temperature | tee temp_string
<TD width='350'>Temperature :</td><td>25 �C</td></tr></table><TABLE width= "100%" border="0" cellpadding='5' cellspacing="0">

Now the problem is how to get the value "25" out from that line im left with. There are 2 <td> tags in this line of html and i cannot figure out the sed expression to save that "25" into a variable that i can use with the rest of my bash script.

Heres one of the examples that didnt work for me:

sed 's/><td\(.*[^<>]\+\?>\)\(.*\)&deg/\2/g' sed_test.txt

Can anyone help me out with this?

you were almost there:

sed 's/.*><td\(.*[^<>]\+\?>\)\(.*\)\&deg.*/\2/g' sed_test.txt

OR

sed 's/.*>\([0-9][0-9]*\).*\&.*/\1/' sed_test.txt
1 Like

Omg it actually works! thank you :slight_smile: