开发者

grep and sed - replace all instances of a string

开发者 https://www.devze.com 2022-12-16 22:25 出处:网络
I have a bash script I\'m writing that greps for a filepat开发者_运维百科h.I want to be able to use the output of the grep to replace each instance of the old filepath with the new filepath.

I have a bash script I'm writing that greps for a filepat开发者_运维百科h. I want to be able to use the output of the grep to replace each instance of the old filepath with the new filepath.

Example:

grep -R "/~test/dev/portal" .

I want to be able to pipe this output into sed to replace each instance of "/~test/dev/portal/" with "/apps/portal/" (keep in mind, the output of the grep is typically more than one file)

Thanks in advance!


grep -ZlR "/~test/dev/portal" . | xargs -0 -l1 sed -i 's:/~test/dev/portal/:/apps/portal/:g'
0

精彩评论

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