1.eval sed ’s/$a/$b/’ filename
2.sed "s/$a/$b/" filename
3.sed ’s/’$a’/’$b’/’ filename
4.sed s/$a/$b/ filename
num.txt
1 2 3
2 1 3
[root@elk_m ~]# sed ''s/"$a"/"$b"/g'' num.txt
1 3 3
3 1 3
m.baidu.com %E5%8D%B0%E5%BA%A6%E6%81%92%E6%B2%B3%E7%9A%84%E6%81%B6%E5%BF%83%E5%9B%BE%E7%89%87 Mozilla/5.0 (Linux; U; Android 4.4.4; zh-cn; S3 Build/KTU84P
m.baidu.com %E8%8E%8E%E6%9C%97%C2%B7%^C
[root@elk_m ~]# ^C
[root@elk_m ~]# ^C
[root@elk_m ~]# for i in `awk -F \) '{print $1}' 1.txt |grep word=|awk -F [\&\"] '{print $2,$NF}'|awk '$1~/word=/{print $0}'|awk -F word= '{print $1,$NF}'|awk '{$1=" ";print "m.baidu.com",$0}'|awk '{print $2}'`;do b=$(printf $(echo -n $i | sed 's/\\/\\\\/g;s/\(%\)\([0-9a-fA-F][0-9a-fA-F]\)/\\x\2/g')"\n") && sed -i ''s/"$i"/"$b"/g'' a.txt;done
[root@elk_m ~]# cat a.txt
m.baidu.com 中日开战普京发誓 Mozilla/5.0 (Linux; Android 4.4.2; Coolpad 8707 Build/KOT49H
m.baidu.com 二战德军军衔 Mozilla/5.0 (Linux; U; Android 4.3; zh-CN; SM-N7508V Build/JLS36C
m.baidu.com 德军山地兵 Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X; zh-CN
m.baidu.com 德军山地兵 Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X; zh-CN
m.baidu.com 李敖评梦鸽救子 Mozilla/5.0 (Linux; Android 5.1.1; HUAWEI M2-803L Build/HUAWEIM2-803L