Delete lines in a text file that contain a specific string and In-place edits with sed on OS X

To remove the line and print the output to standard out:

sed '/pattern to match/d' ./infile

To directly modify the file:

sed -i '/pattern to match/d' ./infile

To directly modify the file (and create a backup):

sed -i.bak '/pattern to match/d' ./infile

For Mac OS X users:

sed -i '' '/pattern/d' ./infile
sed -i '' 's/oldword/newword/' file1.txt
      ^ note the space

Reference links

https://stackoverflow.com/questions/5410757/delete-lines-in-a-text-file-that-contain-a-specific-string

Etiquetas