If you have GNU Grep , you can use -P to make the match inanimate:
$ tr -d \\012 < price.html | grep -Po '<tr>.*?</tr>'
The -P allows you to execute the Perl Compliment (PCRE) regular expression, which is necessary for non-greedy matching with ? because Basic Regular Expression (BRE) and Extended Regular Expression (ERE) do not support it.
If you use -P , you can also use look around to avoid printing tags in the match like this:
$ tr -d \\012 < price.html | grep -Po '(?<=<tr>).*?(?=</tr>)'
If you don't have GNU Grep and the HTML is well-formed, you can simply do:
$ tr -d \\012 < price.html | grep -o '<tr>[^<]*</tr>'
Note. The above example will not work with nested tags inside <tr> .
Chris seymour
source share