If you have GNU Grep
you can use -P
to make the match non-greedy:
$ tr -d \\012 < price.html | grep -Po '<tr>.*?</tr>'
The -P
option enables Perl Compliant Regular Expression (PCRE) which is needed for non-greedy matching with ?
as Basic Regular Expression (BRE) and Extended Regular Expression (ERE) do not support it.
If you are using -P
you could also use look arounds to avoid printing the tags in the match like so:
$ tr -d \\012 < price.html | grep -Po '(?<=<tr>).*?(?=</tr>)'
If you don't have GNU grep
and the HTML is well formed you could just do:
$ tr -d \\012 < price.html | grep -o '<tr>[^<]*</tr>'
Note: The above example won't work with nested tags within <tr>
.