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

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

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?

share|improve this question
In-place editing for sed is not POSIX, which explains why it's not available for you. You could try Perl instead if it's available, since Perl has a -i option that does the same. has some info. Just don't blindly try something without backup! – Daniel Andersson Jan 11 '13 at 13:03
Thanks Daniel. Using perl was the way that worked for me: find . -name "*.java" | xargs perl -pi -e's/foo/bar/g' – user187195 Jan 11 '13 at 13:08
Also asked on StackOverflow: – glenn jackman Jan 11 '13 at 15:50
just take out the xargs and leave the sed. – Tim Kennedy Jan 14 '13 at 3:26

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
share|improve this answer

You could always use ed

find . -name "*.java" | while IFS= read -r file; do
  ed "$file" <<ED_COMMANDS
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.