[英]Using sed command replace in the input text file all occurrences of characters '&', '<', '>' with their HTML entities
this is my input text file这是我的输入文本文件
< > & * ^ % $ # @ ! ) ( ) < > < > > > <
This is the sed shell script that I am using.这是我正在使用的 sed shell 脚本。
sed 's/&/&/g ; s/</</g ; s/>/>/g' html_file.txt > new_file.txt
This is the output file:这是 output 文件:
<lt; >gt; & * ^ % $ # @ ! ) ( ) <lt; >gt; <lt; >gt; >gt; >gt; <lt;
I can't understand that why there is still <
and >
signs instead of &
?我不明白为什么仍然有<
和>
符号而不是&
?
From info sed
:来自info sed
:
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.
Escape &
with \
to \&
.用\
转义&
到\&
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.