开发者

cURL awk { print } help

I have this in a file:

<yweather:condition  text="Partly Cloudy"  code="29"  temp="56"  date="Wed, 23 Feb 2011 6:53 pm MST" />

I'm using this code to try and print "Partly Cloudy", although only "Partly" is not getting printed.

grep "yweather:condition" ~/Documents/weather.dat | awk '{ print $2 }' | awk 'BEGIN { FS = "[\"]" } ; { print $2 } '

Hopefully someone can explain how t开发者_如何学Pythono get both words to print. Thanks!


xmlstarlet sel -t -v "//@text" ~/Documents/weather.dat 2>/dev/null


cat ~/Documents/weather.dat |awk 'BEGIN { FS = "[\"]" } ; /yweather:condition/ { print $2 } '

Replaces all that


$ echo "<yweather:condition  text="Partly Cloudy"  code="29"  temp="56"  date="Wed, 23 Feb 2011 6:53 pm MST" />" | awk '/weather/{gsub(/.*text=|code=.*/,"")}1'
Partly Cloudy

$ echo "<yweather:condition  text="Partly Cloudy"  code="29"  temp="56"  date="Wed, 23 Feb 2011 6:53 pm MST" />" | ruby -e 'puts gets.scan(/text=(.*)code=/)'
Partly Cloudy

If you have more complex situations, use a real XML/HTML parser.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜