Sed and redirection into the same file

"Joshua Bassett" <[email protected]> Fri, 29 Sep 2006 15:53:29 +1000
Newsgroups gmane.org.user-groups.mlug.main
Message-ID <[email protected]>
Hi all,

I was wondering if anyone could help me with a find/replace command I
have been trying to get to work:

for x in `grep -lr 'foo' app | grep -v "svn"`; do sed 's/foo/bar/'
<${x} >${x}; done

I want to replace the word 'foo' with the word 'bar' in all files in
the 'app' directory', except for files in directories that contain
'svn' anywhere in the directory name.

It all appears to work fine, but the problem is when redirecting the
output back into the same file...I end up with empty files! For
example, the following works fine:

for x in `grep -lr 'foo' app | grep -v "svn"`; do sed 's/foo/bar/'
<${x} >${x}.new; done

Clearly it's something to do with the <${x} >${x} part. What am I missing here?

Thanks in advance,

Josh.