Reputation: 858
My question is almost identical to this one: Bash remove everything after </html>. However, the answer
sed -i '/<\/html>/,$d;$a <\/html>' yourfile
is stripping the tag as well. I've tried various of the sed command and | piping another command to re-add the closing tag, but nothing has worked.
In short, i'm trying to remove everything after the tag, even if on the same line or not.
Upvotes: 0
Views: 122
Reputation: 30589
sed -i -n '0,/<\/html>/{s!</html>.*!</html>!;p};q' input
This removes anything after </html>
on the same line and deletes all subsequent lines (just a ;q
added to perreal's first way).
-i
works fine for me (GNU sed 4.2.1).
Upvotes: 0
Reputation: 97948
One way:
sed -n '1,/<\/html>/{s!</html>.*!</html>!;p}' input
Another:
sed -e 's!</html>.*!</html>!' -e '/<\/html>/q' input
Upvotes: 1