2014-07-15 36 views
0

我已经改变值的属性文件。该文件的属性将在第7行如何更改值在属性条目文件中使用shell脚本

baseDir={baseDIR} 
一个条目的条目

上面这行代码中的cat和grep很容易,但我不确定我是如何在“=”后面放入自定义值并将其插入到文件中的。

我想将其更改为

baseDir=/home/db/<new folder>/ 

回答

0

最简单的方法是使用replace实用程序:

[email protected]:~$ cat test.cat 
foo=bar 
zoo=blah 
abc 
def 
1234 
baseDir={baseDir} 
something 
something-else 
[email protected]:~$ replace {baseDir} /home/burhan -- test.cat 
test.cat converted 
[email protected]:~$ cat test.cat 
foo=bar 
zoo=blah 
abc 
def 
1234 
baseDir=/home/burhan 
something 
something-else 

如果不安装(它与MySQL的),你可以使用perl

[email protected]:~$ perl -pi -w -e 's/\/home\/burhan/{baseDir}/g;' < test.cat 
foo=bar 
zoo=blah 
abc 
def 
1234 
baseDir={baseDir} 
something 
something-else 

sed(但你必须m确保你逃脱\字符,如果你要写一条路径):

[email protected]:~$ cat test.cat 
foo=bar 
zoo=blah 
abc 
def 
1234 
baseDir={baseDir} 
something 
something-else 

[email protected]:~$ sed -i 's/{baseDir}/\/home\/burhan\//' test.cat 
[email protected]:~$ cat test.cat 
foo=bar 
zoo=blah 
abc 
def 
1234 
baseDir=/home/burhan/ 
something 
something-else 
相关问题