I have a one line file like this Pastebin but way longer.
My goal is to filter only parts of the string that
example1: start with <a
end with </a>
example2: start with PZ
end with s16
and so in every case keep text in between the match without relying to an html entity
I am on a FreeBSD
and I already have a workaround that rely on html entities
- Beautify to multiline
tidy -i -m -w 160 -ashtml -utf8 ~/file
- Delete lines if not contains string
sed -i '' '/\<\/a\>/!d' ~/file
By the way I am trying to run a direct filter without relying to an html entity. For now I can get only the exact beginning of a match but I don’t know how much is long the string contents I am filtering, so I can’t be precise with the end of the match, see unexpected result steps to reproduce
Steps to reproduce unexpected result
wget -O ~/file https://pastebin.com/raw/xbti369J
grep -E -o ".{0,0}PZ.{0,46}" ~/file
We get wrong lines since we asked fixed lengths
PZ</td><td class="s15">€ 1.20</td><td class="s16
PZ</td><td class="s15"></td><td class="s16">A</t
Goal is to get lines result pattern no matter the length like this below
PZ</td><td class="s15">€ 1.20</td><td class="s16
PZ</td><td class="s15"></td><td class="s16
m/(?<=PZ)(.*?)(?=s16)/g