开发者

grep regex multiple replacements

开发者 https://www.devze.com 2023-03-06 02:48 出处:网络
I will probably have done it \"manually\" by the time I get an answer for this. I have two variables (varA, varB) I want to replace with (a, b) respectively, this currently requires two separate find

I will probably have done it "manually" by the time I get an answer for this.

I have two variables (varA, varB) I want to replace with (a, b) respectively, this currently requires two separate find and replaces.

with regex grep I know how to do two separate searches using v开发者_高级运维arA | varB

but there is no replace function that will similarly do a respective replacement

unless you know better? thanks for any insight


grep is used for searching pattern in a given input. You should use sed for text replacements. For multiple replacements in single sed command just use it like this:

sed -e 's/varA/foo/g' -e 's/varB/bar/g' file.txt
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号