grep the String under subdirectories - --exclude not working
kri shan
Ranch Hand
Joined: Apr 08, 2004
Posts: 1300
posted
0
Following grep command gives list of files has String 'test'.
grep -r -l -c "test" *.* ./ > output.txt
Following command for excluding particular directory is not working.
grep -r -l -c --exclude="\.perforce_path" "test" *.* ./ > output.txt --> not working
How do add word count with following grep command? wl -c
grep -r -l -c --exclude="\.perforce_path" "test" *.* ./ > output.txt
--exclude-dir=DIR
Exclude directories matching the pattern DIR from recursive searches.
Also, the "*.*" is probably not doing what you think it is. Since the command is being pre-processed by your shell, the "*.*" will be interpreted by the shell (not by grep) as being all the files and directories that have at least one '.' in them and will apply to the current directory only; not recursively. It it the "-r" that makes it recursive and applies to all the directories on the tail of your command line except those specifically excluded by a --exclude-dir argument.
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
kri shan wrote:How do add word count with following grep command? wl -c
grep -r -l -c --exclude="\.perforce_path" "test" *.* ./ > output.txt
Your grep commands are mutually exclusive here - the grep man page tells us that:
-l, --files-with-matches
Suppress normal output; instead print the name of each input
file from which output would normally have been printed. The
scanning will stop on the first match.
Therefore there is no point in having both the -l and the -c options to grep, as the list files option will stop the count from succeeding.
I assume you are trying to get a count of the number of files that contain the word test. The command you want is wc (for word count), not wl, and the wc -l will count lines, which I think makes sense.
Presumably you want to continue having the output go to output.txt while simultaneously getting a line count? If so, then you probably want to use the tee command. Now you can have a command like:
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: grep the String under subdirectories - --exclude not working