-1
div class="panel-body" id="current-conditions-body">
    <!-- Graphic and temperatures -->
    <div id="current_conditions-summary" class="pull-left" >
                    <img src="newimages/large/sct.png" alt="" class="pull-left" />
                    <p class="myforecast-current">Partly Cloudy</p>
        <p class="myforecast-current-lrg">64&deg;F</p>
        <p class="myforecast-current-sm">18&deg;C</p>

I try to extract the "64" in line 6, I was thinking to use awk '/<p class="myforecast-current-lrg">/{print}', but this only gave me the full line. Then I think I need to use sed, but i don't know how to use sed.

markp-fuso
  • 28,790
  • 4
  • 16
  • 36

1 Answers1

0

Assumptions:

  • input is nicely formatted as per the sample provided by OP so we can use some 'simple' pattern matching

Modifying OP's current awk code:

# use split() function to break line using dual delimiters ">" and "&"; print 2nd array entry

awk '/<p class="myforecast-current-lrg">/{ n=split($0,arr,"[>&]");print arr[2]}'

# define dual input field delimiter as ">" and "&"; print 2nd field in line that matches search string

awk -F'[>&]' ' /<p class="myforecast-current-lrg">/{print $2}'

Both of these generate:

64

One sed idea:

sed -En 's/.*<p class="myforecast-current-lrg">([^&]+)&deg.*/\1/p'

This generates:

64
markp-fuso
  • 28,790
  • 4
  • 16
  • 36