Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!caip!rutgers!sri-spam!nike!ucbcad!ucbvax!ernie.Berkeley.EDU!phr From: phr@ernie.Berkeley.EDU (Paul Rubin) Newsgroups: net.emacs Subject: Re: regular expressions and operations other than replace Message-ID: <16200@ucbvax.BERKELEY.EDU> Date: Mon, 20-Oct-86 15:48:20 EDT Article-I.D.: ucbvax.16200 Posted: Mon Oct 20 15:48:20 1986 Date-Received: Tue, 21-Oct-86 23:45:24 EDT References: <1168@peregrine.UUCP> <403@lewey.UUCP> Sender: usenet@ucbvax.BERKELEY.EDU Reply-To: phr@ernie.Berkeley.EDU.UUCP (Paul Rubin) Organization: University of California, Berkeley Lines: 44 In article <403@lewey.UUCP> evp@lewey.UUCP (Ed Post) writes: >> Since I have switched from vi to EMACS, there is one thing that I missed >> more than anything else. The ability to perform an operation on all >> the lines that met a particular criteria(specified by a regular expression). >> For instance in vi, I could type in "/[A-Z][a-z]*/d" to delete all lines >> that met the specified criteria or I could type in >> "/\([A-Za-z][A-Za-z]*(\).*\()\)/s//\1\2". How would I do similar operations >> in EMACS? > >There are several answers to this question. The easiest way to do >exactly what you want is to pipe the file through sed... Ugh!! The first thing to try when figuring out things like this is the Apropos command. You can also get more detailed documentation from the Emacs Info file: type C-h I, then look through the Command Index and Concept Index nodes til you find what you want. In this case, you get the following descriptions. You can also bring in the Lisp source for these commands to see how they work or to modify them to do anything you want on matching (non-matching, etc.) lines. File: emacs Node: Other Repeating Search, Prev: Replace, Up: Search Other Search-and-Loop Commands ============================== Here are some other commands that find matches for a regular expression. They all operate from point to the end of the buffer. `M-x list-matching-lines' Print each line that follows point and contains a match for the specified regexp. A numeric argument specifies the number of context lines to print before and after each matching line; the default is none. `M-x count-matches' Print the number of matches following point for the specified regexp. `M-x delete-non-matching-lines' Delete each line that follows point and does not contain a match for the specified regexp. `M-x delete-matching-lines' Delete each line that follows point and contains a match for the specified regexp.