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

This is a discussion on Why does `grep --exclude=.svn` not work? - Unix ; 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 ...

+ Reply to Thread
Results 1 to 8 of 8

Thread: Why does `grep --exclude=.svn` not work?

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

    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

  2. Re: Why does `grep --exclude=.svn` not work?

    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?displa...3020;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.


  3. Re: Why does `grep --exclude=.svn` not work?

    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)




  4. Re: Why does `grep --exclude=.svn` not work?

    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.

  5. Re: Why does `grep --exclude=.svn` not work?

    2007-03-14, 12:23(+00), Adam Funk:
    [...]
    >> You could use find(1) instead of grep -r to ignore .svn directories,
    >> or try a grep replacement ...

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

  6. Re: Why does `grep --exclude=.svn` not work?

    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 *


    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;
    }


  7. Re: Why does `grep --exclude=.svn` not work?

    Another option is this:
    find . -type d \( -name .svn -o -name ignore1 -o -name ignore2 \) -prune -o -type f -print0 |xargs -0r grep --color "$@"

  8. Re: Why does `grep --exclude=.svn` not work?

    Or a pretty easy way is this:

    grep .... | grep -v .svn

    This takes the original result and then pipes it into a second grep excluding lines containing .svn
    Not as efficient as ignoring the .svn dirs in the first place but it'll work and it's easy to remember.

+ Reply to Thread