Delete (non) matching lines

Recently I needed to clean up a pile of text I had pasted into emacs from a pdf. One of the things I wanted was to remove all lines that didn’t start with a comma. Emacs of course provides functions for this, so I highlighted the text and used M-x delete-non-matching-lines ^,

The ^, is a regular expression that matches lines starting with a comma. Emacs also offers the command delete-matching-lines which does what you would expect.

Advertisement

2 comments

  1. Just a note to say that delete-non-matching-lines is an alias for keep-lines; delete-matching-lines is an alias for flush-lines.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s