* How to find lines not matching a certain pattern - ie grep -v
@ 2015-02-22 18:11 gnuist006
2015-02-22 20:40 ` Dan Espen
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: gnuist006 @ 2015-02-22 18:11 UTC (permalink / raw)
To: help-gnu-emacs
Hi All,
Once in a while I have to do something to lines that do not have a certain string or set of strings in them. I know how to find lines with a string. I also know how to find lines with a set of strings, ie by using the regexp
string1\|string2\| ....
But I dont know how to find strings that do not have the string or strings.
For the moment, I have been doing this in bash using grep -v. I assume that this is also doable in awk and possibly sed. But I dont know how to do this in a direct manner in emacs.
One indirect method in emacs would be to search for the lines with the strings and label/mark them with # in the beginning.
Next, label/mark all the lines with @ in the beginning.
Next, replace all the @#'s in the beginning with # or even nothing, ie ""
Now, you can search for all the lines with @ in the beginning and do whatever to them.
I assume that this is such a common operation that there would be something cleaner and better for this in emacs already.
Cheers
Bolega
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to find lines not matching a certain pattern - ie grep -v
2015-02-22 18:11 How to find lines not matching a certain pattern - ie grep -v gnuist006
@ 2015-02-22 20:40 ` Dan Espen
2015-02-22 22:01 ` ltolenaar
2015-02-22 20:55 ` Drew Adams
2015-02-23 3:23 ` Barry Margolin
2 siblings, 1 reply; 7+ messages in thread
From: Dan Espen @ 2015-02-22 20:40 UTC (permalink / raw)
To: help-gnu-emacs
gnuist006@gmail.com writes:
> Hi All,
>
> Once in a while I have to do something to lines that do not have a
> certain string or set of strings in them. I know how to find lines
> with a string. I also know how to find lines with a set of strings, ie
> by using the regexp
>
> string1\|string2\| ....
>
> But I dont know how to find strings that do not have the string or strings.
>
> For the moment, I have been doing this in bash using grep -v. I assume
> that this is also doable in awk and possibly sed. But I dont know how
> to do this in a direct manner in emacs.
>
> One indirect method in emacs would be to search for the lines with the
> strings and label/mark them with # in the beginning.
>
> Next, label/mark all the lines with @ in the beginning.
>
> Next, replace all the @#'s in the beginning with # or even nothing, ie ""
>
> Now, you can search for all the lines with @ in the beginning and do whatever to them.
>
>
> I assume that this is such a common operation that there would be
> something cleaner and better for this in emacs already.
M-x grep
then enter the string followed by -v then the filename pattern.
--
Dan Espen
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to find lines not matching a certain pattern - ie grep -v
2015-02-22 20:40 ` Dan Espen
@ 2015-02-22 22:01 ` ltolenaar
2015-02-25 1:29 ` Robert Thorpe
0 siblings, 1 reply; 7+ messages in thread
From: ltolenaar @ 2015-02-22 22:01 UTC (permalink / raw)
To: help-gnu-emacs
The grep -v may not work if it is not installed as is likely to be the case on windows. Apparently what is needed is a true grep implementation in compiled elisp. I would be glad to do this if there are substantial pointers or instruction.
Linda
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to find lines not matching a certain pattern - ie grep -v
2015-02-22 22:01 ` ltolenaar
@ 2015-02-25 1:29 ` Robert Thorpe
0 siblings, 0 replies; 7+ messages in thread
From: Robert Thorpe @ 2015-02-25 1:29 UTC (permalink / raw)
To: ltolenaar; +Cc: help-gnu-emacs
ltolenaar@gmail.com writes:
> The grep -v may not work if it is not installed as is likely to be the
> case on windows. Apparently what is needed is a true grep
> implementation in compiled elisp. I would be glad to do this if there
> are substantial pointers or instruction.
If your on MS Windows there are plenty of ways to get Grep. It's
available in Eli Zaretski's ezwinports:
http://sourceforge.net/projects/ezwinports/
That also includes find, man, diff, groff, make, gnutls and a bunch of
other useful GNU programs. There's MinGW, MinGW2 and GNUWin32 for all
the stuff it doesn't cover (I use MinGW).
Vincent Goulet supplies an Emacs for MS Window which comes with some of
these things (though not grep, AFAIK).
Making a grep replacement in elisp would certainly be possible but it
would be slow. Emacs regexps aren't fast and neither is it's byte-code
interpreter. Performance is quite critical for Grep.
There is a "find" replacement in Emacs, find-lisp.el,
e.g. find-lisp-find-dired. It's useful if you're stuck without a port
of GNU find, but it's not as fast and doesn't have the same features.
If your looking for a project making an MS Win distribution of Emacs
with all the GNU utilities it uses would be a good one.
BR,
Robert Thorpe
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: How to find lines not matching a certain pattern - ie grep -v
2015-02-22 18:11 How to find lines not matching a certain pattern - ie grep -v gnuist006
2015-02-22 20:40 ` Dan Espen
@ 2015-02-22 20:55 ` Drew Adams
2015-02-23 3:23 ` Barry Margolin
2 siblings, 0 replies; 7+ messages in thread
From: Drew Adams @ 2015-02-22 20:55 UTC (permalink / raw)
To: gnuist006, help-gnu-emacs
> Once in a while I have to do something to lines that do not have a certain
> string or set of strings in them. I know how to find lines with a string. I
> also know how to find lines with a set of strings, ie by using the regexp
> string1\|string2\| ....
>
> But I dont know how to find strings that do not have the string or strings.
A. If you use Icicles then:
1. You can complement the search domain (the set of search contexts).
In the case of `icicle-occur', which is analogous to `occur' and `grep',
the search contexts are lines, so searching with complementing means
searching the lines that do not match the context-defining regexp.
You can use `C-M-~' anytime during Icicles search, to toggle whether to
search the originally defined search contexts or their complements.
http://www.emacswiki.org/emacs/Icicles_-_Search_Commands%2c_Overview#SearchOutsideContexts
2. #1 is about complementing the set of search contexts, that is, the
regions of text that you define initially and then search incrementally.
Another, more common kind of complementing is to complement the set of
current search hits, on the fly.
For that, you hit `C-~'. That is the Icicles way to complement the
current set of completion candidates, to show those from the initial
domain (or the last narrowing via `S-SPC') that do not belong to the
current set of hits. So you type a pattern to match, and then hit
`C-~', to see all of the thingies that do NOT match that pattern.
http://www.emacswiki.org/emacs/Icicles_-_Nutshell_View#ChippingAway
B. If you use library `isearch-prop.el' then you can get another kind
of complementing with Isearch:
You can search zones of text/overlays that have a given property, or
you can search the complement: the zones that do NOT have a given
property. You can toggle this search-domain complementing at any time
during Isearch, using `C-M-~'.
http://www.emacswiki.org/emacs/IsearchPlus#isearchp-toggle-complementing-domain
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to find lines not matching a certain pattern - ie grep -v
2015-02-22 18:11 How to find lines not matching a certain pattern - ie grep -v gnuist006
2015-02-22 20:40 ` Dan Espen
2015-02-22 20:55 ` Drew Adams
@ 2015-02-23 3:23 ` Barry Margolin
2015-02-23 4:20 ` Michael Heerdegen
2 siblings, 1 reply; 7+ messages in thread
From: Barry Margolin @ 2015-02-23 3:23 UTC (permalink / raw)
To: help-gnu-emacs
In article <6a41f4ac-f7e7-49f1-a593-501d82d4c733@googlegroups.com>,
gnuist006@gmail.com wrote:
> Hi All,
>
> Once in a while I have to do something to lines that do not have a certain
> string or set of strings in them. I know how to find lines with a string. I
> also know how to find lines with a set of strings, ie by using the regexp
>
> string1\|string2\| ....
>
> But I dont know how to find strings that do not have the string or strings.
You could copy the buffer to another buffer, then use M-x flush-lines to
delete the matching lines. What's left are the non-matching lines.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to find lines not matching a certain pattern - ie grep -v
2015-02-23 3:23 ` Barry Margolin
@ 2015-02-23 4:20 ` Michael Heerdegen
0 siblings, 0 replies; 7+ messages in thread
From: Michael Heerdegen @ 2015-02-23 4:20 UTC (permalink / raw)
To: help-gnu-emacs
Barry Margolin <barmar@alum.mit.edu> writes:
> You could copy the buffer to another buffer, then use M-x flush-lines
> to delete the matching lines. What's left are the non-matching lines.
AFAIK "color-moccur" has a key for just that. It is quite comfortable
and efficient for doing such things when you don't want to rely on any
large package like Icicles.
Michael.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2015-02-25 1:29 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-22 18:11 How to find lines not matching a certain pattern - ie grep -v gnuist006
2015-02-22 20:40 ` Dan Espen
2015-02-22 22:01 ` ltolenaar
2015-02-25 1:29 ` Robert Thorpe
2015-02-22 20:55 ` Drew Adams
2015-02-23 3:23 ` Barry Margolin
2015-02-23 4:20 ` Michael Heerdegen
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.