[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Remove all lines containig a keyword
RE: Remove all lines containig a keyword
Fri, 3 Oct 2008 10:06:49 -0400
Hide-lines.el is also useful
from the commentary...
;; Now, when you type C-c h, you will be prompted for a regexp
;; (regular expression). All lines matching this regexp will be
;; hidden in the buffer.
;; Alternatively, you can type C-u C-c h (ie. provide a prefix
;; argument to the hide-lines command) to hide all lines that *do not*
;; match the specified regexp.
;; If you want to make all of the hidden areas re-appear again, type:
;; M-x show-all-invisible
;; Or you can bind show-all-invisible to a key and use that to show
;; all the hidden areas again.
And from the emacs manual...
20.10 Other Search-and-Loop Commands
Here are some other commands that find matches for a regular
expression. They all ignore case in matching, if the pattern contains
no upper-case letters and `case-fold-search' is non-`nil'. Aside from
`occur' and its variants, all operate on the text from point to the end
of the buffer, or on the active region in Transient Mark mode.
`M-x occur <RET> REGEXP <RET>'
Display a list showing each line in the buffer that contains a
match for REGEXP. To limit the search to part of the buffer,
narrow to that part (*note Narrowing::). A numeric argument N
specifies that N lines of context are to be displayed before and
after each matching line. Currently, `occur' can not correctly
handle multiline matches.
The buffer `*Occur*' containing the output serves as a menu for
finding the occurrences in their original context. Click
`Mouse-2' on an occurrence listed in `*Occur*', or position point
there and type <RET>; this switches to the buffer that was
searched and moves point to the original of the chosen occurrence.
`o' and `C-o' display the match in another window; `C-o' does not
After using `M-x occur', you can use `next-error' to visit the
occurrences found, one by one. *Note Compilation Mode::.
Synonym for `M-x occur'.
`M-x multi-occur <RET> BUFFERS <RET> REGEXP <RET>'
This function is just like `occur', except it is able to search
through multiple buffers. It asks you to specify the buffer names
one by one.
`M-x multi-occur-in-matching-buffers <RET> BUFREGEXP <RET> REGEXP <RET>'
This function is similar to `multi-occur', except the buffers to
search are specified by a regular expression that matches visited
file names. With a prefix argument, it uses the regular
expression to match buffer names instead.
`M-x how-many <RET> REGEXP <RET>'
Print the number of matches for REGEXP that exist in the buffer
after point. In Transient Mark mode, if the region is active, the
command operates on the region instead.
`M-x flush-lines <RET> REGEXP <RET>'
This command deletes each line that contains a match for REGEXP,
operating on the text after point; it deletes the current line if
it contains a match starting after point. In Transient Mark mode,
if the region is active, the command operates on the region
instead; it deletes a line partially contained in the region if it
contains a match entirely contained in the region.
If a match is split across lines, `flush-lines' deletes all those
lines. It deletes the lines before starting to look for the next
match; hence, it ignores a match starting on the same line at which
another match ended.
`M-x keep-lines <RET> REGEXP <RET>'
This command deletes each line that _does not_ contain a match for
REGEXP, operating on the text after point; if point is not at the
beginning of a line, it always keeps the current line. In
Transient Mark mode, if the region is active, the command operates
on the region instead; it never deletes lines that are only
partially contained in the region (a newline that ends a line
counts as part of that line).
If a match is split across lines, this command keeps all those
SEI | 1 Freedom Valley Drive | Oaks, PA 19456 | p: 610-676-1279 | f:
484-676-1279 | www.seic.com
From: address@hidden [mailto:address@hidden On Behalf Of Bourgneuf Francois
Sent: Friday, October 03, 2008 9:54 AM
To: Chris Patterson; address@hidden
Subject: RE: Remove all lines containig a keyword
C-M-% .*sold.*C-q C-j Enter !
I explain :
C-M-% : query-replace-regexp
.*sold.*C-q C-j : 0-n character followed by "sold" followed by 0-n character
followed by NEWLINE ( C-q C-j )
> -----Message d'origine-----
> De :
> address@hidden De la part de Chris Patterson
> Envoyé : lundi 29 septembre 2008 04:46
> À : address@hidden
> Objet : Re: Remove all lines containig a keyword
> Christian Herenz <address@hidden> writes:
> > Hi,
> > I have a huge list of "stuff" I sell / sold.
> > To print out an actual list, without the stuff that is sold already,
> > It would be nice to have a command for doing this task automated -
> > Remove all lines with the keyword "sold".
> > Thanks for your Help,
> > Christian
> Looks like you have several suggestions. I'll chime in with M-x