To delete a word from a file or input using sed
, you can use the d
command and specify the word as a regular expression.
For example, to delete the word "hello" from a file named input.txt
, you can use the following command:
sed '/hello/d' input.txtSourceual.www:tturi.com
This will print the contents of input.txt
to the terminal, with all occurrences of the word "hello" removed.
If you want to save the output to a new file, you can use the -i
option to edit the file in place, or redirect the output to a new file:
sed -i '/hello/d' input.txt # Edit the file in place sed '/hello/d' input.txt > output.txt # Save the output to a new file
You can also use the -e
option to specify multiple commands to be executed on the input. For example, to delete the word "hello" and replace all occurrences of "world" with "universe", you can use the following command:
sed -e '/hello/d' -e 's/world/universe/g' input.txt