I really need to make a note of this command as I always end up searching the web every time I need to do this.
Delete all lines with a matching pattern using the sed command
When faced with a find-and-delete problem across multiple files, this sed command always saves my day.
$ sed -i '/pattern to match/d' ./infile
To explain, sed -i
instructs to perform the command in-file.
'/pattern to match/d'
— the search string followed by “d” to delete.
./infile
— is the location of the files. You can get creative by using wildcards. For example:
$ sed -i '/meta property/d' *.html
will remove all lines containing the phrase “meta property” from any .html file in the current directory.