在<body ...>之后插入Sed

Ste*_*hen 1 regex bash sed

我想在开始<body...>标记之后添加一行html ,但是没有任何换行符,所以这对我来说有点困难.

例如,我想<p>This is the first line</p><body...>标记之后插入,我从文本文件调用:

<html><head><title>Some title</title></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Some text goes here

我到目前为止所尝试的所有内容仅在匹配字符串的第一个换行符之后插入.当身体造型总是不同时,我如何插入身体后?

anu*_*ava 5

不建议用sed操纵HTML.但是你可以尝试:

sed -i.bak 's~<body[^>]*>~&<p>This is the first line</p>~' file.html
Run Code Online (Sandbox Code Playgroud)