help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: grep-find oddity


From: Tom Roche
Subject: Re: grep-find oddity
Date: Mon, 22 Mar 2010 12:56:09 -0400
User-agent: GNU Emacs 23.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version 2.18.0)

[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>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]