Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .