Bash remove everything after </html>

2019-08-13 02:35发布

One of my clients' sites has been hacked, and there is iframe injection in every file. However, the iframe injection is always after the closing </html> tag.

Is there an easy way using Bash to remove everything after the </html> tag using something like sed?

E.g.:

</html>
p
<nofollow><iframe src="http://xxxxx.com/local.html" width="0" height="0" frameborder="0"></iframe></nofollow>
p
<nofollow><iframe src="http://xxxxx.com/local.html" width="0" height="0" frameborder="0"></iframe></nofollow>

标签: replace sed
2条回答
地球回转人心会变
2楼-- · 2019-08-13 03:05

Just quit when you hit the line:

sed -i '/<\/html>/q' file
查看更多
欢心
3楼-- · 2019-08-13 03:18

This is what you are looking for:

 sed -i '/<\/html>/,$d;$a <\/html>' yourfile

Updated to delete lines until the end of the file

查看更多
登录 后发表回答