0

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?

Cyrus
  • 84,225
  • 14
  • 89
  • 153

2 Answers2

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