Originally Posted by
OmahaVike
here's how i'm parsing some weather data from the gov. xml file looks something like:
Code:
blah blah blah
blah blah blah
blah blah blah
<temperature_string>9 F (-13 C)</temperature_string>
<temp_f>9</temp_f>
<temp_c>-13</temp_c>
<relative_humidity>80</relative_humidity>
<wind_string>From the Northeast at 10 MPH</wind_string>
<wind_dir>Northeast</wind_dir>
and the awk (think it may actually be gawk) code following will only snag the stuff between the <temp_f> and </temp_f> tags:
Code:
awk '/temp_f/ {gsub(/<temp_f>/,"",$0);gsub(/<\/temp_f>/,"",$1);print}' filename.xml
hope this helps someone in need.
this is an old thread. anyway, the awk statement can be shortened
Code:
awk '/temp_f/ {gsub(/<temp_f>|<\/temp_f>/,"");print $0}' file
Bookmarks