unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* grep-find oddity
@ 2010-03-22  3:38 Tom Roche
  2010-03-22  4:07 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Roche @ 2010-03-22  3:38 UTC (permalink / raw)
  To: help-gnu-emacs


I'm running ubuntu=karmic package=emacs-snapshot, which is

GNU Emacs 23.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version 2.18.0)
 of 2009-09-27 on crested, modified by Debian

When I do M-x grep-find with the argument

find . -type f -name '*.10*' -print0 | xargs -0 -e grep -nH -e '<respiratory>'

I get

*grep*
> -*- mode: grep; default-directory: "~/info/logs/" -*-
> Grep started at Sun Mar 21 23:27:38
>
> find . -type f -name '*.10*' -print0 | xargs -0 -e grep -nH -e '<respiratory>'
> ./logfile.100103:326:<respiratory>
> ./logfile.100110:529:<respiratory>
> ./logfile.100117:217:<respiratory>
> ./logfile.100124:186:<respiratory>
> ./logfile.100131:387:<respiratory>
> ./logfile.100207:836:<respiratory>
> ./logfile.100307:265:<respiratory>
> ./logfile.100214:271:<respiratory>
> ./logfile.100221:402:<respiratory>
> ./logfile.100314:488:<respiratory>
> ./logfile.100228:311:<respiratory>
> ./logfile.100321:731:<respiratory>
>
> Grep finished (matches found) at Sun Mar 21 23:27:38

which I expect. But when I try to do M-x grep-find with a nearly
equivalent but slightly more complex argument

find . -type f -name '*.10*' -print0 | sort | xargs -0 -e fgrep -nH -e '<respiratory>'

I get

*grep*
> -*- mode: grep; default-directory: "~/info/logs/" -*-
> Grep started at Sun Mar 21 23:23:15
>
> find . -type f -name '*.10*' -print0 | sort | xargs -0 -e fgrep -nH -e '<respiratory>'
> ./logfile.100103:326:<respiratory>
> ./logfile.100110:529:<respiratory>
> ./logfile.100117:217:<respiratory>
> ./logfile.100124:186:<respiratory>
> ./logfile.100131:387:<respiratory>
> ./logfile.100207:836:<respiratory>
> ./logfile.100307:265:<respiratory>
> ./logfile.100214:271:<respiratory>
> ./logfile.100221:402:<respiratory>
> ./logfile.100314:488:<respiratory>
> ./logfile.100228:311:<respiratory>
> ./logfile.100321:731:<respiratory>
> fgrep: 
> : No such file or directory
>
> Grep exited abnormally with code 123 at Sun Mar 21 23:23:15

The latter seems wrong:
- output is unsorted: same 12 results, no change in order
- fgrep gets error (though it's in the path, works fine from xterm)
- grep exits abnormally

So I'm wondering:

0 Why does grep-find behave like this?

1 What should I do to process a more complex pipeline, but otherwise
  get grep-find behavior (i.e. present results in a buffer from which
  I can navigate to results)?

Apologies if this is a FAQ, but I didn't see anything in the *info*
(node=emacs, page=31.4 Searching with Grep under Emacs).

TIA, Tom Roche <Tom_Roche@pobox.com>




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: grep-find oddity
  2010-03-22  3:38 grep-find oddity Tom Roche
@ 2010-03-22  4:07 ` Eli Zaretskii
  2010-03-22 16:56   ` Tom Roche
  0 siblings, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2010-03-22  4:07 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Tom Roche <Tom_Roche@pobox.com>
> Date: Sun, 21 Mar 2010 23:38:01 -0400
> 
> 
> But when I try to do M-x grep-find with a nearly
> equivalent but slightly more complex argument
> 
> find . -type f -name '*.10*' -print0 | sort | xargs -0 -e fgrep -nH -e '<respiratory>'
> 
> I get
> 
> *grep*
> > -*- mode: grep; default-directory: "~/info/logs/" -*-
> > Grep started at Sun Mar 21 23:23:15
> >
> > find . -type f -name '*.10*' -print0 | sort | xargs -0 -e fgrep -nH -e '<respiratory>'
> > ./logfile.100103:326:<respiratory>
> > ./logfile.100110:529:<respiratory>
> > ./logfile.100117:217:<respiratory>
> > ./logfile.100124:186:<respiratory>
> > ./logfile.100131:387:<respiratory>
> > ./logfile.100207:836:<respiratory>
> > ./logfile.100307:265:<respiratory>
> > ./logfile.100214:271:<respiratory>
> > ./logfile.100221:402:<respiratory>
> > ./logfile.100314:488:<respiratory>
> > ./logfile.100228:311:<respiratory>
> > ./logfile.100321:731:<respiratory>
> > fgrep: 
> > : No such file or directory
> >
> > Grep exited abnormally with code 123 at Sun Mar 21 23:23:15
> 
> The latter seems wrong:
> - output is unsorted: same 12 results, no change in order
> - fgrep gets error (though it's in the path, works fine from xterm)
> - grep exits abnormally

Try "sort -z" instead of just "sort".  By default, `sort' assumes
lines are separated by newlines, not by null characters.





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: grep-find oddity
  2010-03-22  4:07 ` Eli Zaretskii
@ 2010-03-22 16:56   ` Tom Roche
  2010-03-22 17:49     ` Suvayu Ali
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Roche @ 2010-03-22 16:56 UTC (permalink / raw)
  To: help-gnu-emacs


[thread regarding perceived oddity of behavior of
M-x grep-find argument="find . -type f -name '*.10*' -print0 | sort |
                        xargs -0 -e fgrep -nH -e '<respiratory>'"
starts @
http://lists.gnu.org/archive/html/help-gnu-emacs/2010-03/msg00181.html
]

Eli Zaretskii Mon, 22 Mar 2010 06:07:15 +0200
> Try "sort -z" instead of just "sort".

<auto-dopeslap/> Thanks! I should have noted the semantics of -print0.
Of course, M-x grep-find with

find . -type f -name '*.10*' -print0 | sort -z | xargs -0 -e fgrep -nH -e '<respiratory>'

gets the desired result

*grep*
> -*- mode: grep; default-directory: "~/info/logs/" -*-
> Grep started at Mon Mar 22 12:31:07
>
> find . -type f -name '*.10*' -print0 | sort -z | xargs -0 -e fgrep -nH -e '<respiratory>'
> ./logfile.100103:326:<respiratory>
> ./logfile.100110:529:<respiratory>
> ./logfile.100117:217:<respiratory>
> ./logfile.100124:186:<respiratory>
> ./logfile.100131:387:<respiratory>
> ./logfile.100207:836:<respiratory>
> ./logfile.100214:271:<respiratory>
> ./logfile.100221:402:<respiratory>
> ./logfile.100228:311:<respiratory>
> ./logfile.100307:265:<respiratory>
> ./logfile.100314:488:<respiratory>
> ./logfile.100321:731:<respiratory>
>
> Grep finished (matches found) at Mon Mar 22 12:31:07

Note that the default argument offered for grep-find uses -print0. I'm
wondering, why? since invoking 

find . -type f -name '*.10*' -print | sort | xargs -e fgrep -nH -e '<respiratory>'

also works:

*grep*
> -*- mode: grep; default-directory: "~/info/logs/" -*-
> Grep started at Mon Mar 22 12:36:06
>
> find . -type f -name '*.10*' -print | sort | xargs -e fgrep -nH -e '<respiratory>'
> ./logfile.100103:326:<respiratory>
> ./logfile.100110:529:<respiratory>
> ./logfile.100117:217:<respiratory>
> ./logfile.100124:186:<respiratory>
> ./logfile.100131:387:<respiratory>
> ./logfile.100207:836:<respiratory>
> ./logfile.100214:271:<respiratory>
> ./logfile.100221:402:<respiratory>
> ./logfile.100228:311:<respiratory>
> ./logfile.100307:265:<respiratory>
> ./logfile.100314:488:<respiratory>
> ./logfile.100321:731:<respiratory>
>
> Grep finished (matches found) at Mon Mar 22 12:36:06

Using the special null-string-terminating argument to 'find' without
subsequent use with *all* further components of the pipeline the user
might want to build (e.g. '-z' with 'sort', '-0' with 'xargs') will
result in error (e.g. no results, or no linkage from the results to the
underlying files). Thus the default offered seems (to me, and I Could Be
Wrong) to be a likely source of error. Am I missing something? Or is
there an overriding motivation for making null-string termination the
default?

thanks for the tip, Tom Roche <Tom_Roche@pobox.com>




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: grep-find oddity
  2010-03-22 16:56   ` Tom Roche
@ 2010-03-22 17:49     ` Suvayu Ali
  0 siblings, 0 replies; 4+ messages in thread
From: Suvayu Ali @ 2010-03-22 17:49 UTC (permalink / raw)
  To: help-gnu-emacs

On 22/03/10 09:56 AM, Tom Roche wrote:
> Wrong) to be a likely source of error. Am I missing something? Or is
> there an overriding motivation for making null-string termination the
> default?
>

It is a shell thing. With a null string terminated list, its easier to 
deal with file names with special characters.

> thanks for the tip, Tom Roche<Tom_Roche@pobox.com>
>

HTH
-- 
Suvayu

Open source is the future. It sets us free.




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-03-22 17:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-22  3:38 grep-find oddity Tom Roche
2010-03-22  4:07 ` Eli Zaretskii
2010-03-22 16:56   ` Tom Roche
2010-03-22 17:49     ` Suvayu Ali

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).