0

I am trying to extract a data (temperature) from a text file downloaded from wget.

eg. wget http://www.weatherzone.com.au/sa/adelaide/adelaide

How to I extract the information which is "18.6" from the file and copy it to another file to be used by another application?

less adelaide
---snip---
'<span id="top_obs_temp" class="tempnow">18.6&deg;C</span>'
---snip---

TIA

A.B.
  • 90,397

1 Answers1

0

Use awk

$ wget http://www.weatherzone.com.au/sa/adelaide/adelaide
$ awk  -F '[<|>|&]' '/tempnow/ {print $3}' adelaide
20.0

or all-in-one

$ wget -q -O- http://www.weatherzone.com.au/sa/adelaide/adelaide | awk  -F '[<|>|&]' '/tempnow/ {print $3}' 
20.1

This works as long as the attribute class with the value tempnow is available in the span tag.

<span id="top_obs_temp" class="tempnow">18.6&deg;C</span>

And now I'm blacklisted o_O :P

wget http://www.weatherzone.com.au/sa/adelaide/adelaide                                                  
--2015-11-06 08:17:37--  http://www.weatherzone.com.au/sa/adelaide/adelaide
Resolving www.weatherzone.com.au (www.weatherzone.com.au)... 104.101.241.181
Connecting to www.weatherzone.com.au (www.weatherzone.com.au)|104.101.241.181|:80... connected.
HTTP request sent, awaiting response... 403 Forbidden
2015-11-06 08:17:37 ERROR 403: Forbidden.

A.B.
  • 90,397
  • using awk +1 =) – Ravan Nov 06 '15 at 12:31
  • TTP request sent, awaiting response... 403 Forbidden 2015-11-06 08:17:37 ERROR 403: Forbidden.

    --- is that what it is? I also get the same thing now :( --- I can't test awk now since I am getting blocked as well

    – vileharp Nov 10 '15 at 01:25
  • I will check it today again. I could start the script 5 times? – A.B. Nov 10 '15 at 04:36