stringsedgrepgeektool

how do I delete text after last period


I am using Nerdtool on and iMac running OSx 10.6.8 and have written some code to get a weather report and display it on my desktop. How do I delete the text after the last period beginning with "Forcast issued"? A second issue I noticed is that the text returned has a 'space' in front of the first character. I'd like that gone too. Below is the command and output I get using Terminal. Thanks.

Command:

curl --silent "http://weather.gc.ca/rss/city/on-137_e.xml" | grep -E '(Weather Forecasts:|</summary)'| head -3 | sed -e 's/<summary type=\"html\">//' -e 's/<\/summary>//' -e 's/]]> //' -e 's/No watches or warnings in effect. //'

Output:

Sunny this morning then a mix of sun and cloud with 40 percent chance of showers this afternoon. Risk of a thunderstorm this afternoon. Wind becoming west 20 km/h this afternoon. High 29. UV index 8 or very high. Forecast issued 05:00 AM EDT Friday 31 July 2015


Solution

  • You already know how to use sed s to delete text. You can target the front of the line with ^ and the end of the line with $. So you can delete the space at the beginning with: -e 's/^ //' And delete Forecast issued to the end of the line with: -e 's/ Forecast issued.*$//'