意外替换为&与sed [英] Unexpected substitution for & with sed

查看:88
本文介绍了意外替换为&与sed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CSV文件,其中包含一些特殊字符及其HTML实体名称

I have a CSV file containing some special characters and their HTML entity names

例如:htm.csv

À,À
Á,Á
Â,Â
Ã,Ã
É,É
Ê,Ê
Í,Í
Ó,Ó
Ô,Ô
Õ,Õ

,我有许多.php文件,这些文件中有这些特殊字符.我已经写了一个shell脚本

and I have a number of .php files where these special characters are present. I have written a shell script

#!/bin/bash
IFS=","
while read orig html
do
   for fl in *.php; do
   mv $fl $fl.old
   sed 's/'$orig'/'$html'/g' $fl.old > $fl
   done
done< "htm.csv"

但是问题是当使用$html的内容时,它正在打印$orig的内容而不是"&".

but the problem is when using the contents of $html, it is printing the contents of $orig instead of "&".

推荐答案

&是一个特殊字符,在s///命令中表示整个匹配的字符串".使用\&.

& is a special character meaning "the whole matched string" in the s/// command. Use \&.

这篇关于意外替换为&amp;与sed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆