Если вам не нужно быстрое и грязное решение, синтаксический анализ html должен выполняться с использованием синтаксического анализатора html, как сказано в комментариях.
Например, с использованием python:
import bs4 # bs4 stands for beautifulsoup, a html parser
import csv
# I open both input and output file
with open(<input>) as myinput, open(<output>, "w") as myoutput:
# I parse the html
soup = bs4.BeautifulSoup(myinput, 'html.parser')
# I set the delimiter for the csv
csvwriter = csv.writer(myoutput, delimiter="|")
# For each tr tag
for tr in soup.find_all('tr'):
# Here I create a list that contains all text from td
rows = [td.text for td in tr.find_all('td')]
# I write the 4th first values as a csv row
csvwriter.writerow(rows[:4])
Теперь, если вы не уверены в этом хорошем решении, давайте посмотрим на быстрое и грязное, используя awk:
awk '
# I define here input and output delimiters
BEGIN{FS="<|>"; OFS=" | "}
# I store info in array td_info
/<td>/{td_info[++counter]=$3}
# I print the info I need and clean td_info array and counter
/<\/tr>/{
print td_info[1], td_info[2], td_info[3], td_info[4]
counter=0
delete td_info
}
' <input.html>
Вывод:
Dec 1, 2019 11:12 PM | some text1 | some text2 | some text3
Dec 5, 2019 4:33 PM | some text1 | some text2 | some text3
Dec 9, 2019 1:06 PM | some text1 | some text2 | some text3