我在这里遇到了另一个使用 SED 的问题。我想向字符串中添加一些文本,但不更改每行不同的特定单词。或者将代码包装在字符串上,使其保持原样。
例如:FROM
<font color="#000000"><p align="JUSTIFY">COAT. how are you.
<font color="#000000"><p align="JUSTIFY">MONEY.Where are you.
<font color="#000000"><p align="JUSTIFY">FOOD.what are you.
<font color="#000000"><p align="JUSTIFY">CAR.which are you.
<font color="#000000"><p align="JUSTIFY">QUALITY.When are you.
到
<b><font color="#000000"><p align="JUSTIFY">COAT.</b>how are you.
<b><font color="#000000"><p align="JUSTIFY">MONEY.</b>Where are you.
<b><font color="#000000"><p align="JUSTIFY">FOOD.</b>what are you.
<b><font color="#000000"><p align="JUSTIFY">CAR.</b>which are you.
<b><font color="#000000"><p align="JUSTIFY">QUALITY.</b>When are you.
再次提前致谢。问候。
答案1
sed 's/\./\0<\/b>/g' < FileName
它会查找所有出现的“。”并将其替换为“。”
sed 's/\.$/\0<\/b>/' < FileName
它在行尾找到“。”并将其替换为“。”
(sed 's/\.$/\0<\/b>/' | sed 's/^/\0<b>/') < FileName
它在行尾找到“。”并将其替换为“。”,并在行首附加“”