使用sed命令在输入文本文件中替换所有出现的字符“&”、“”及其HTML实体
这是我的输入文本文件使用sed命令在输入文本文件中替换所有出现的字符“&”、“”及其HTML实体,sed,html-entities,ampersand,Sed,Html Entities,Ampersand,这是我的输入文本文件 < > & * ^ % $ # @ ! ) ( ) < > < > > > < 这是我正在使用的sedshell脚本 sed 's/&/&/g ; s/</</g ; s/>/>/g' html_file.txt > new_file.txt 这是输出文件: <lt; >gt; & * ^ % $ # @ !
< > & * ^ % $ # @ ! ) ( ) < > < > > > <
这是我正在使用的sedshell脚本
sed 's/&/&/g ; s/</</g ; s/>/>/g' html_file.txt > new_file.txt
这是输出文件:
<lt; >gt; & * ^ % $ # @ ! ) ( ) <lt; >gt; <lt; >gt; >gt; >gt; <lt;
我不明白为什么信息sed中仍然有符号而不是&?:
用\ to\&.逃逸&这是否回答了您的问题?
3.3 The 's' Command
[...]
The 's' command (as in substitute) is probably the most important in
'sed' [...]. The syntax of the 's' command is 's/REGEXP/REPLACEMENT/FLAGS'.
[...]
The REPLACEMENT can contain [...] unescaped '&' characters which reference the
whole matched portion of the pattern space.