我想改变一个文本中与bourne
shell中另外一个字匹配的单词.例如:
- hello sara,my name is sara too.
变为:
- hello mary,my name is mary too.
有谁能够帮助我?
我知道grep找到相似的单词,但我想用其他单词替换它们.
解决方法
纯bash语法:
- before='hello sara,my name is sara too .'
- after=${before//sara/mary}
- echo $after
或sed语法:
- sed 's/sara/mary/g' <<< $before
- echo $after
OUTPUT:
- hello mary,my name is mary too .