如何删除上一节后的文字
how do I delete text after last period
我在 iMac 运行 OSx 10.6.8 上使用 Nerdtool 并编写了一些代码来获取天气预报并将其显示在我的桌面上。如何删除最后一段以 "Forcast issued" 开头的文本?我注意到的第二个问题是返回的文本在第一个字符前面有一个 'space'。我也希望它消失。
下面是我使用终端获得的命令和输出。
谢谢
命令:
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. //'
输出:
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
您已经知道如何使用 sed s
删除文本。您可以使用 ^
定位行首,使用 $
定位行尾。所以你可以删除开头的 space :
-e 's/^ //'
并删除 Forecast issued
到行尾:
-e 's/ Forecast issued.*$//'
我在 iMac 运行 OSx 10.6.8 上使用 Nerdtool 并编写了一些代码来获取天气预报并将其显示在我的桌面上。如何删除最后一段以 "Forcast issued" 开头的文本?我注意到的第二个问题是返回的文本在第一个字符前面有一个 'space'。我也希望它消失。 下面是我使用终端获得的命令和输出。 谢谢
命令:
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. //'
输出:
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
您已经知道如何使用 sed s
删除文本。您可以使用 ^
定位行首,使用 $
定位行尾。所以你可以删除开头的 space :
-e 's/^ //'
并删除 Forecast issued
到行尾:
-e 's/ Forecast issued.*$//'