sed replace

图灵

1
2
3
4
5
6
7
8
9
10
11
sed -i 's/\\"//g' file
sed -i 's/\\\\\//\//g' file
sed -i 's/"\[{""json"":""/\[/g' file
sed -i 's/{""json"":""//g' file
sed -i 's/"",""mt"":[0-9]*}\]"/\]/g' file
sed -i 's/"",""mt"":[0-9]*}//g' file

Use double quotes so that sed would expand variables.

sed "s|\$ROOT|${HOME}|" abc.sh

  • shell变量在双引号内会被解析
  • 在单引号内不会被解析

How to use variables in a command in sed?