03.03.05
Curl Sed and Grep
Below are a couple of commands that I’m using with Geektool to display the Weather forecast and the UV index for the Portland area on my desktop:
echo -n "Next Rain: "; curl -s -m 4 PUTTHEURLHERE
| sed 's/showers/rain/g' | grep 'rain' | sed 's/<br /><br />/|/g;'
| tr "|" "\n" | grep 'rain' | sed q
| sed s'/< \/b>: /|/g' | tr "|" "\n" | sed s'/\< \b\>//g' | sed q
Where it says “PUTTHEURLHERE” you would use the proper URL for your region’s forecast. In my case, for Portland Oregon it is this one and be sure to put ” backslashes in front of each of the ‘&’ ampersands.
Here’s the one for the UV Index:
echo -n "PDX UV: "; curl -s
http://www.cpc.ncep.noaa.gov/products/stratosphere/uv_index/bulletin.txt
| grep -E '(PORTLAND OR)' | awk '{print $6}'
Each of the two commands should be entered on one line, without any line breaks. These can be easily modified to focus on any other NOAA region.
**Question:** Why would Ross subject himself to the horrors of sed and awk and grep in this way?
**Answer:** The UV index is good to know because of the patch of skin cancer that I got last year. I like to know if it’s going to be okay to drive with Viva’s convertible top off, or if I should keep covered up. The Weather forecast is for Viva as well. Knowing when it’s likely to rain let’s me know when I need to put her tarp over her. Oh… have you met Viva yet?