I was trying to replace all instances of "unix"(ignore cases) to "oracle". So, I cat the "testfile2" and pipe and after sed I redirected back to the same file "testfile2". But the file becomes empty. Can someone please help debug.
bash-3.2$ cat testfile2
uniX
udfi
unix
UNix
UNIX
Unix
ockcl
cunci
bash-3.2$ cat testfile2 |tr [A-Z] [a-z] |sed 's/unix/oracle/g' > testfile2
bash-3.2$ cat testfile2
bash-3.2$
I was able to get a workaround using a tee as follows, but couldn't figure why redirection didn't work.
bash-3.2$ cat testfile2 |tr [A-Z] [a-z] |sed 's/unix/oracle/g' |tee testfile2
oracle
udfi
oracle
oracle
oracle
oracle
ockcl
cunci
bash-3.2$ cat testfile2
oracle
udfi
oracle
oracle
oracle
oracle
ockcl
cunci
I'm using bash version 3.2.57(1)-release (solaris2.10)