Unix questions - Why does `grep --exclude=.svn` not work?

This is Interesting: Free IT Magazines  
Home > Archive > Unix questions > March 2007 > Why does `grep --exclude=.svn` not work?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Why does `grep --exclude=.svn` not work?
Adam Funk

2007-03-13, 7:24 am

Using GNU grep 2.5.1, I want to grep recursively through a subversion
sandbox without seeing all the duplicates in the .svn/ subtrees. All
the following fail to exclude them:

grep -r --exclude=.svn getURL *
grep -r --exclude=.svn/ getURL *
grep -r --exclude=/.svn/ getURL *
grep -r --exclude='*/.svn/*' getURL *
grep -r --exclude='.svn/*' getURL *

What am I doing wrong?

Thanks,
Adam
parv

2007-03-13, 7:17 pm

in message <2oeic4-acg.ln1@news.ducksburg.com>,
wrote Adam Funk ...

> Using GNU grep 2.5.1, I want to grep recursively through a subversion
> sandbox without seeing all the duplicates in the .svn/ subtrees. All
> the following fail to exclude them:
>
> grep -r --exclude=.svn getURL *
> grep -r --exclude=.svn/ getURL *
> grep -r --exclude=/.svn/ getURL *
> grep -r --exclude='*/.svn/*' getURL *
> grep -r --exclude='.svn/*' getURL *


My grep(1) states ...

--exclude=PATTERN
Recurse in directories skip file matching PATTERN.


.... which, to me, given your observation seems to imply that
--exclude option applies only to non-directory files (or file-file,
not everything-(including a directory)-is-a-file).

You could use find(1) instead of grep -r to ignore .svn directories,
or try a grep replacement ...

tcgrep:
http://www.mail-archive.com/ppt@perl.org/msg00014.html
http://search.cpan.org/~cwest/ppt-0.14/bin/grep

diotalevi's grep:
http://perlmonks.org/index.pl?displ...73020;replies=1

ack:
http://search.cpan.org/~petdance/ack/ack


- parv

--
As nice it is to receive personal mail, too much sweetness causes
tooth decay. Unless you have burning desire to contact me, do not do
away w/ WhereElse in the address for private communication.

Harry331

2007-03-14, 1:19 am

Adam Funk wrote...
>
>Using GNU grep 2.5.1, I want to grep recursively through a subversion
>sandbox without seeing all the duplicates in the .svn/ subtrees. All
>the following fail to exclude them:
>
> grep -r --exclude=.svn getURL *
> grep -r --exclude=.svn/ getURL *
> grep -r --exclude=/.svn/ getURL *
> grep -r --exclude='*/.svn/*' getURL *
> grep -r --exclude='.svn/*' getURL *
>
>What am I doing wrong?


man grep says

--exclude=PATTERN
Recurse in directories skip file matching PATTERN.

Perhaps you need to read this statement more carefully.
Skip file .... not skip folder.

You may get a clue from the following runs.

$ cat xx
getURL

$ cat .svn/xx
getURL

$ grep -r -l getURL *
xx
<-- well, it's already skipped the .svn folder

$ grep -r -l --exclude=x* getURL *
<-- nothing returned .... PATTERN is x* (match xx)



Adam Funk

2007-03-14, 7:26 am

On 2007-03-13, parv wrote:

> My grep(1) states ...
>
> --exclude=PATTERN
> Recurse in directories skip file matching PATTERN.


Mine too. Often in Unixese a directory is considered a type of file...


> ... which, to me, given your observation seems to imply that
> --exclude option applies only to non-directory files (or file-file,
> not everything-(including a directory)-is-a-file).


....but apparently here "file" means "non-directory file"!


> You could use find(1) instead of grep -r to ignore .svn directories,
> or try a grep replacement ...


Thanks for the suggestions.
Stephane CHAZELAS

2007-03-14, 1:24 pm

2007-03-14, 12:23(+00), Adam Funk:
[...]
>
> Thanks for the suggestions.


Or do a chmod 0 .svn

Or, with zsh:

(assuming you have setopt extendedglob)

grep ... (^.svn/)##*(D-.)

or simply

grep ... **/*(-.)

as zsh will ommit dot files and dot dirs by default.

(-.) is for regular files or symlinks to regular files. To
descend into symlinks as grep does (but you probably don't want
that), replace "**" with "***".

--
Stéphane
Dave Gibson

2007-03-15, 7:24 pm

Adam Funk <a24061@yahoo.com> wrote:
> Using GNU grep 2.5.1, I want to grep recursively through a subversion
> sandbox without seeing all the duplicates in the .svn/ subtrees. All
> the following fail to exclude them:
>
> grep -r --exclude=.svn getURL *
> grep -r --exclude=.svn/ getURL *
> grep -r --exclude=/.svn/ getURL *
> grep -r --exclude='*/.svn/*' getURL *
> grep -r --exclude='.svn/*' getURL *


For files not named on the command line, only the basename is compared
to the exclude pattern.

Try one of these:

find * -name '.svn' -prune -o -type f -exec \
grep -- getURL /dev/null \{\} +

find * -type f -exec \
grep --exclude='*.svn/*' -- getURL /dev/null \{\} +

Or try to apply the following patch (watch out for the tabs):

--- grep-2.5.1a/lib/savedir.c.orig 2001-03-04 05:33:12.000000000 +0000
+++ grep-2.5.1a/lib/savedir.c 2007-03-15 17:09:59.000000000 +0000
@@ -137,10 +137,10 @@
&& !isdir1 (dir, dp->d_name))
{
if (included_patterns
- && !excluded_filename (included_patterns, dp->d_name, 0))
+ && !excluded_filename (included_patterns, path, 0))
continue;
if (excluded_patterns
- && excluded_filename (excluded_patterns, dp->d_name, 0))
+ && excluded_filename (excluded_patterns, path, 0))
continue;
}

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com