2

I have a bash script I'm writing that greps for a filepath. 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!

1
  • Check on ServerFault for these kind of answers. Jan 14, 2010 at 18:02

1 Answer 1

6
grep -ZlR "/~test/dev/portal" . | xargs -0 -l1 sed -i 's:/~test/dev/portal/:/apps/portal/:g'
2
  • 1
    grep -Z | xargs -0 just in case Jan 14, 2010 at 18:41
  • Dennis, good arguments! I haven't even thought about using them for this (I guess I have to study the man pages more). grep -ZlR "/~test/dev/portal" . | xargs -0 -l1 sed -i 's:/~test/dev/portal/:/apps/portal/:g' Jan 14, 2010 at 20:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.