如:helloaawordcc
结果:hello11word22
把aa替换成11,cc替换成22,怎么替换两个变量,我想到的是用sed要读写两次,感觉太繁琐,应该有更好的方法吧,各位前辈给指导下,谢谢了先!
求问在在shell脚本里同一行怎么替换多个不同的字符变量?谢谢!
-
- 帖子: 2
- 注册时间: 2016-11-14 14:44
- 系统: Mac
-
- 帖子: 992
- 注册时间: 2007-12-05 10:57
- 系统: ubuntu14.04
- 来自: 金山
Re: 求问在在shell脚本里同一行怎么替换多个不同的字符变量?谢谢!
代码: 全选
echo "helloaawordcc" | sed 's/aa/11/;s/cc/22/'
-
- 帖子: 2
- 注册时间: 2016-11-14 14:44
- 系统: Mac
Re: 求问在在shell脚本里同一行怎么替换多个不同的字符变量?谢谢!
谢谢大神cao627 写了:代码: 全选
echo "helloaawordcc" | sed 's/aa/11/;s/cc/22/'
- jiandan23
- 帖子: 86
- 注册时间: 2010-12-17 22:31
- 系统: Mint 19.2
Re: 求问在在shell脚本里同一行怎么替换多个不同的字符变量?谢谢!
或者用tr:echo helloaawordcc | tr "ac" "12"