Answer the question
In order to leave comments, you need to log in
How to do multiple substitutions in sed?
How to do exactly sequential replacements in one sed so that you can apply immediately to the file using the -i switch?
There is this (combing HTML table to CSV):
sed -e '/\(html\|title\|body\|table\)/d' -e 's/ \{2,\}//g' /dev/shm/ex01.html | \
sed ':a;N;$!ba;s#\s*</td>\s*</tr>\s*<tr>\s*<td>\s*#\n#g' | \
sed ':b;N;$!bb;s#\s*</td>\s*<td>\s*#;#g' | \
sed '/\(tr>\|<td\|td>\)/d'
':b;N;$!bb;s#\s*</td>\s*<td>\s*#;#g'
, and for some reason deletion only works at the beginning of the file, it does not delete at the end. PS: don't look Answer the question
In order to leave comments, you need to log in
basically figured it out...
after the commands
:a;N;$!bathe whole text becomes one line, so regular expressions are needed a little differently, see below:
sed '/title/d
:a;N;$!ba
s/ \{2,\}//g
s#\s*</td>\s*</tr>\s*<tr>\s*<td>\s*#\n#g
s#\s*</td>\s*<td>\s*#;#g
s/<[^>]\+>//g
s/\n\{2,\}//g' /dev/shm/ex01.html
### Convert HTML to CSV
sed ':a;N;$!ba
s/<html.\+<table[^>]\+>//Ig
s#\s*</td>\s*</tr>\s*<tr>\s*<td>\s*#\n#Ig
s#\s*</td>\s*<td>\s*#;#Ig
s/<[^>]\+>//g;s/\s\{2,\}//g' somreport.html
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question