Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用shell脚本更改属性文件中条目的值_Shell - Fatal编程技术网

如何使用shell脚本更改属性文件中条目的值

如何使用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

我必须更改属性文件中某个条目的值。属性文件的第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}
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