[net.emacs] regular expressions and operations

prestat@uicsl.UUCP (10/23/86)

All the responses to the question about using regular
expressions to select lines seem to be non-responsive.
While phr gave a useful summary from the manual that
points out that there IS a command to do the particular
example the questioner used, that was just an example,
not the whole question.

There ought to be a function to map another function
over the lines of the file, preferably with an re
filter.  On the other hand, it really wouldn't be hard to
write one.  You just need a function that takes a
string (the regular expression) and a function (to be
applied to matching lines) and loops over the buffer
looking for matching lines and applying the function.
I haven't memorized GNU function names, so I won't try
to write the function here.

You could also have a map-over-re-strings function that
stepped through the matching REs in the buffer and applied
the function to each.

For non-GNU users, you can delete matching lines in Unipress
by using hard newlines.  That is, turn
newline.*pattern.*newline into newline.  You can get a
newline in your patterns by quoting control-j.

--
scott preece
PREECE@GSWD-VMS.ARPA

mike@peregrine.UUCP (Mike Wexler) (10/30/86)

In article <4300002@uicsl> prestat@uicsl.UUCP writes:
>All the responses to the question about using regular
>expressions to select lines seem to be non-responsive.

Enclosed is a summary of the responses I got via e-mail summary of them
are quite helpful.  BTW I have edited these.

>scott preece
>PREECE@GSWD-VMS.ARPA
-------------------------------------------------------------------------------
From: felix!hplabs!weemba@brahms.berkeley.edu (Matthew P Wiener)

(while (looking-at "regular expression") (action-1) (action 2) ...)

You can execute this without programming, by using ESC ESC to do a one-time
evaluation.  If you don't know what the names associated to certain key
actions are and can't find them in the manual, look at C-h c to get the
name.  Sometimes you need specific arguments for an action, C-h k or C-h f
will give you the details.  Have fun.

ucbvax!brahms!weemba	Matthew P Wiener/UCB Math Dept/Berkeley CA 94720
-----------------------------------------------------------------------------
From: felix!hplabs!ucbvax!phr@ernie.berkeley.edu (Paul Rubin)

>From the Emacs Info file (found by looking for "delete-matching-lines"
in the Command Index):

  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.


From: felix!trwrb!trwspp!spp2!urban (Mike Urban)

Easy.  Filter the buffer through a "sed" command.  As with many
Unix techniques, I haven't decided whether this method is wonderfully
elegant, or an awful kludge.  It *is*, however, very useful.  If you
find yourself doing it a lot, you can even have some key bound to a function
that prompts you for the sed command and does the work.

   Mike Urban
-------------------------------------------------------------------------------
From: Bob Chassell <ccicpg!seismo!harvard!lmi-angel!bob>


The easiest thing to do is write a keyboard macro and then apply it
generally. Look up the online documentation with control-h i, get into
the manual and then look for regexps and for keyboard macros.  (It
looks like there are a lot of nodes in the table of contents for the
manual but you can search for regexp and macro.)  

Bob Chassell




-- 
Mike Wexler
(trwrb|scgvaxd)!felix!peregrine!mike
(714)855-3923