3

I am trying to do a recursive find and replace in HP-UX and am missing something.

What I have at the moment:

find . -name "*.java" | xargs sed 's/foo/bar/g'

I know the problem is that it's not replacing the file inline. I believe on other OS's there is a -i flag, but it seems in my HP-UX version, there isn't.

Any suggestions?

4
1

you could workaround the missing -i like this (untested):

for i in `find . -name "*.java"`; do cp $i /tmp/$$; sed 's/foo/bar/g' < /tmp/$$ > $i;done
1

You could always use ed

find . -name "*.java" | while IFS= read -r file; do
  ed "$file" <<ED_COMMANDS
%s/foo/bar/g
w
q
ED_COMMANDS
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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