Linux / Unix: Sed Delete Matching Words In A File

by on January 21, 2011 · 0 comments· LAST UPDATED December 24, 2012

in , ,

I have a file called rsnapshot.conf. It has the words "ssh_args=-p 1222". How do I match and remove (delete) the words "ssh_args=-p 1222" from config file using sed command under Linux or Unix like operating systems?

You can use the the substitute sed command changes all occurrences of the "ssh_args=-p 1222". The same command can be used to delete the required words.
Tutorial details
DifficultyEasy (rss)
Root privilegesNo
Requirementssed
Estimated completion timeN/A

Sed command syntax to remove words

The syntax is:

sed 's/word-to-find//g' input.file > output.file

Gnu/sed syntax:
sed -i 's/word-to-find//g' input.file

Examples

Type the following command

 
sed  -i 's/ssh_args=-p 1222//g' input.file
sed  -i 's/ssh_args=-p 1222//g' /etc/rsnapshot.conf
 
TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 0 comments… add one now }

Leave a Comment

Tagged as: , ,

Previous Faq:

Next Faq: