Text substitution (reading from file and saving to the same file) on linux with sed...
        Posted  
        
            by 
                Roger
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Roger
        
        
        
        Published on 2011-06-26T13:47:57Z
        Indexed on 
            2011/06/27
            0:22 UTC
        
        
        Read the original article
        Hit count: 241
        
I want to read the file "teste", make some "find&replace" and overwrite "teste" with the results. The closer i got till now is:
$cat teste
I have to find something
This is hard to find...
Find it wright now!
$sed -n 's/find/replace/w teste1' teste
$cat teste1
I have to replace something
This is hard to replace...
If I try to save to the same file like this:
$sed -n 's/find/replace/w teste' teste
or:
$sed -n 's/find/replace/' teste > teste
The result will be a blank file...
I know I am missing something very stupid but any help will be welcome.
UPDATE: Based on the tips given by the folks and this link: http://idolinux.blogspot.com/2008/08/sed-in-place-edit.html here's my updated code:
sed -i -e 's/find/replace/g' teste 
        © Stack Overflow or respective owner