如何使用shell脚本更改属性文件中条目的值
我必须更改属性文件中某个条目的值。属性文件的第7行将有一个条目,如下所示如何使用shell脚本更改属性文件中条目的值,shell,Shell,我必须更改属性文件中某个条目的值。属性文件的第7行将有一个条目,如下所示 baseDir={baseDIR} 上面这行的cat和grep很简单,但我不确定如何在=之后输入自定义值并将其插入文件中 我想把它改成 baseDir=/home/db/<new folder>/ 最简单的方法是使用该实用程序: 如果未安装,它随MySQL一起提供,您可以使用perl: burhan@sandbox:~$ cat test.cat foo=bar zoo=blah abc def 1234
baseDir={baseDIR}
上面这行的cat和grep很简单,但我不确定如何在=之后输入自定义值并将其插入文件中
我想把它改成
baseDir=/home/db/<new folder>/
最简单的方法是使用该实用程序: 如果未安装,它随MySQL一起提供,您可以使用perl:
burhan@sandbox:~$ cat test.cat
foo=bar
zoo=blah
abc
def
1234
baseDir={baseDir}
something
something-else
burhan@sandbox:~$ replace {baseDir} /home/burhan -- test.cat
test.cat converted
burhan@sandbox:~$ cat test.cat
foo=bar
zoo=blah
abc
def
1234
baseDir=/home/burhan
something
something-else
burhan@sandbox:~$ perl -pi -w -e 's/\/home\/burhan/{baseDir}/g;' < test.cat
foo=bar
zoo=blah
abc
def
1234
baseDir={baseDir}
something
something-else
burhan@sandbox:~$ cat test.cat
foo=bar
zoo=blah
abc
def
1234
baseDir={baseDir}
something
something-else
burhan@sandbox:~$ sed -i 's/{baseDir}/\/home\/burhan\//' test.cat
burhan@sandbox:~$ cat test.cat
foo=bar
zoo=blah
abc
def
1234
baseDir=/home/burhan/
something
something-else