Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Given the following find command: find . | xargs grep 'userTools' -sl

How can I use sed on the results of that command?


share|improve this question
What do you want sed to do? –  Dennis Williamson Sep 20 '10 at 20:48
Yes sorry I didn't clarify before. I need sed to replace the contents of each file in the list –  Kyle Hayes Sep 20 '10 at 21:35

3 Answers 3

up vote 4 down vote accepted

I am assuming that you want to perform some sed operation on the contents of each of the files rather than on the list of file names since you seem to know how to do that already. The answer depends in part on the version of sed you have available. If it supports the -i option (edit files in place), you could use xargs again like this:

find . | xargs grep 'userTools' -sl | xargs -L1 sed -i 's/this/that/g'

If your sed doesn't have the -i option, you could do this instead:

find . | xargs grep 'userTools' -sl | while read file
sed 's/this/that/g' "$file" > tmpfile
mv tmpfile "$file"
share|improve this answer
find . -print0 | xargs -0 grep -slZ 'userTools' | xargs -0 sed -i 's/foo/bar/'


find . -print0 | xargs -0 sed -i '/userTools/ s/foo/bar/'


ack -l --print0 'userTools' | xargs -0 sed -i 's/foo/bar/'
share|improve this answer
find \Path_where_files_are -type f -name 'file_type' -exec  sed -e 's/"text_to_be_changed"/"text_to_be_changed_to"/' {} +
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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