Penguin

Extremely handy hint

In sed, you don't have to use "/" to separate your statement.

sed 's/this/that/g' is the same as sed 's#this#that#g'.

How can I EDIT a file using sed?

Use the -i switch. This means that the file you supply to sed is overwritten with the changes made by sed. If you don't want to lose the original file then after the -i switch you can add a backup extension.

For example:

  • sed -i.bkp '1,2d' test.txt

This will edit test.txt and the original file can be found in test.txt.bkp