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?

2 Answers2

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
sparkie
  • 2,268
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
glenn jackman
  • 27,524