shell脚本编程流水笔记
2015-11-28 14:41
344 查看
此篇文章主要目的是记录一些工作中的shell相关流水笔记。
1、在shell编程的时候,在shell脚本中调用命令需要用`` 将命名包起来才能正常执行。
2、
sed -in-place ‘s/8080/8001/g’ /home/work/server.xml
但是如果需要把8001改成变量,如
sed -in-place ’s/8080/$port/g‘ /home/work/server.xml
这样就不成功。
此时需要把单引号改成双引号,如下边例子
$port=8001
sed -in-place "s/8080/$port/g" /home/work/server.xml
----------------------------------------------------------------------------------------------------
通过shell脚本替换属性文件中的某行记录
假设有如下属性文件 demo.properties
user.name=test
user.password=123456
...............................
需求:先需要通过shell 脚本将 user.name 和 user.password 的value值替换为实际需要的用户名和密码,
将可以通过如下方式实现:
sed -i "s#^user.name=.*#user.name=用户名#g" path/demo.properties
sed -i "s#^user.password=.*#user.password=密码#g" path/demo.properties
这样demo属性文件中的内容即被替换掉了。
-----------------------------------------------------------------------------------------------------
3、
1、在shell编程的时候,在shell脚本中调用命令需要用`` 将命名包起来才能正常执行。
2、
sed 中使用变量---------------------------------------------
一般在sed 中替换都用单引号,如下边sed -in-place ‘s/8080/8001/g’ /home/work/server.xml
但是如果需要把8001改成变量,如
sed -in-place ’s/8080/$port/g‘ /home/work/server.xml
这样就不成功。
此时需要把单引号改成双引号,如下边例子
$port=8001
sed -in-place "s/8080/$port/g" /home/work/server.xml
----------------------------------------------------------------------------------------------------
通过shell脚本替换属性文件中的某行记录
假设有如下属性文件 demo.properties
user.name=test
user.password=123456
...............................
需求:先需要通过shell 脚本将 user.name 和 user.password 的value值替换为实际需要的用户名和密码,
将可以通过如下方式实现:
sed -i "s#^user.name=.*#user.name=用户名#g" path/demo.properties
sed -i "s#^user.password=.*#user.password=密码#g" path/demo.properties
这样demo属性文件中的内容即被替换掉了。
-----------------------------------------------------------------------------------------------------
3、
相关文章推荐
- Linux shell学习
- CentOS 6.7编写Shell脚本实现简单跳板机功能
- 正则表达式 后向引用
- Shell学习笔记 - 分支语句
- Hbase快速开始——shell操作
- 常用的shell脚本
- shell从1加到100
- 【原】Gradle调用shell脚本和python脚本并传参
- shell 和 环境变量
- shell两行合并成一行
- 用shell脚本写一个for循环
- shell用到的命令
- 在mysql中执行shell命令
- Shell case正则匹配法
- shell函数
- linux shell “(())” 双括号运算符使用
- CentOS 设置快捷键启动Shell终端
- Hbase常用Shell命令
- crontab定时器(包括执行shell)
- linux在shell中获取时间