For example I have a caf.txt file and I want to delete a "donut" word in the document without entering the document on linux .How can I do it?
            Asked
            
        
        
            Active
            
        
            Viewed 208 times
        
    0
            
            
         
    
    
        Cyrus
        
- 84,225
- 14
- 89
- 153
 
    
    
        Mertcan Kavuker
        
- 15
- 5
- 
                    You want to delete just the word or the line containing that word? – Utsav Dec 22 '16 at 06:50
- 
                    line containing that word – Mertcan Kavuker Dec 22 '16 at 06:55
- 
                    1Then check Mike's answer and accept it so the question could be closed. Thanks – Utsav Dec 22 '16 at 06:59
- 
                    It took less than a minute to find a duplicate. – anishsane Dec 22 '16 at 07:22
2 Answers
3
            To delete just the word "donut"
sed -i 's/donut//g' caf.txt
To delete lines that contain the word "donut"
sed -i '/donut/d' caf.txt
 
    
    
        Mike JS Choi
        
- 1,081
- 9
- 19
0
            
            
        What I do is:
sed '/text_to_delete/d' filename | sponge filename
This will make the change to the source file.
 
    
    
        Divyang Shah
        
- 1,578
- 1
- 11
- 22