iT邦幫忙

0

What is wrong with the current sed command for parsing an HTML?

Here is the part of 1.html

<table width="100%" cellpadding="2" cellspacing="1">
    <tr bgcolor="#FF0000">
      <td><center><h3 id="nr_status">FAILED<h3></center></td>
    </tr>
    </table>
    <b>1 tests have been read.</b><br />
    <b>1 tests have been executed.</b><br />
    <b>0 tests have been ignored.</b><br />
    <b>0 tests have suceeded.</b><br />
    <b>1 tests have failed.</b><br />

I do not know much about linux but I was exploring StreamEditor, the objective is to set the value FAILED in a variable. So I tried to write a code

sed -n '/<h3 id="nr_status">/,/<\/h3>/p'  ~/1.html

The output i got is everything after , not sure why is not being considered as a matching pattern ?

KYC World iT邦新手 5 級 ‧ 2020-06-29 07:59:21 檢舉
Just only HTML? Or you have another backend program to support this?

1 個回答

1
海綿寶寶
iT邦大神 1 級 ‧ 2020-06-29 08:51:46

試試看

sed -n '/<h3 id="nr_status">[[:print:]]*<h3>/gm'  ~/1.html

推薦一個 RE 的網站
可以先測試看看你設的 RE 找不找得到
Regex 101

balasahu iT邦新手 5 級 ‧ 2020-06-29 12:20:03 檢舉

Thank you so much for your reply. Will try this.

我要發表回答

立即登入回答