Friday, October 02, 2009

Delete a line with sed

I wrote about how append a new line using sed. Now let me copy here how to erase or delete a line using sed if that line has a pattern.

If you want to erase, for instance a line that starts with # character, you should use something like:
sed -e '/^#/d'

If your text comes from a command you may use a pipe by doing something like:
cat /etc/services | sed -e '/^#/d'
or if you want to use on a certain file:
sed -e '/^#/d' fileName.ext
Hope it helps someone...

Labels: ,