修改配置文件内容的shell
2012-03-24 20:15
260 查看
#!/bin/sh function updateConfigLine() { confFile=$1 lineKey=$2 lineValue=$3 if [ -z $1 -o -z $2 -o -z $3 ]; then echo "parameters not match function:updateConfigLine()" exit 1 fi count=`grep $lineKey $confFile|wc -l|tr -d [BLANK]` if [ $count -eq 0 ]; then echo "not found $lineKey in file: $confFile" exit 1 fi if [ $count -gt 1 ]; then echo "found more then one lines of $lineKey in file: $confFile" exit 1 fi sed "s/$lineKey.*=.*/$lineKey=$lineValue/g" $confFile > "$confFile"tmpforautoreplace cat "$confFile"tmpforautoreplace > $confFile rm -f "$confFile"tmpforautoreplace echo "change to $lineKey=$lineValue in file $confFile successfully" } function help() { echo "run this shell with parameters like below." echo "$0 filePathName itemKey itemvalue" } file=$1 key=$2 value=$3 validate=1 [ -z $1 ] && validate=0; [ -z $2 ] && validate=0; [ -z $3 ] && validate=0; if [ $validate == 0 ]; then echo "please input right parameters" help exit 1 fi updateConfigLine $1 $2 $3
相关文章推荐
- shell脚本修改配置文件中的内容
- 四行代码动态修改web.config文件appsettings配置节内容
- lunix下shell脚本批量获取文件,批量修改文件内容
- linux shell 发送email 邮件【文章内容仅供参考,有些地方可能不正确,默认只能在局域网,公网需要修改配置文件】
- shell脚本获取配置文件中的内容
- 安装盘启动系统,挂载硬盘,然后进入shell模式修改配置文件
- shell脚本获取配置文件中的内容
- 用代码修改配置文件(app.config)的内容
- ruby on rails 修改配置文件或修改yml文件的内容
- Shell自动修改CentOS6网卡配置文件
- C语言读取及修改简单配置文件内容
- shell脚本获取配置文件中的内容
- linux通过shell脚本修改文件内容
- Application_Start事件中修改配置文件内容
- 批量修改文件名称或者文件内容的shell脚本
- shell修改配置文件
- shell脚本获取配置文件中的内容
- 安装配置Hadoop的各个配置文件修改的地方以及修改的内容
- 没有动任何配置文件,今天就出现了修改的JSP内容在页面不体现。依然是老的页面内容
- shell脚本获取配置文件中的内容