2

I think its a simple question, but the answer is probably a little more complicated :P

Edit: Actually, its not complicated at all!^^

So I have a directory with multiple svn projects and I would like to search through all recent files (in trunk folder) by content in all projects.

Here is somewhat the folders look like:

Projects
|
->Project1
|   |
|   ->tags
|   |
|   ->trunk
|
->Project2
|   |
|   ->tags
|   |
|   ->trunk
...
  • 3
    grep -l some-pattern ./Projects/Project*/trunk/*? Or more specific requirements? – grebneke Mar 4 '14 at 13:26
  • well the projects aren't really named ProjectX, but I guess ./Projects/*/trunk/* should do :) – Alko Mar 4 '14 at 14:07
3

As suggested in comments above:

grep -l some-pattern ./Projects/*/trunk/*

or recursively if there are subdirs under each trunk (and your grep supports -r):

grep -lr some-pattern ./Projects/*/trunk/
  • @StephaneChazelas - thanks for the edit. POSIX does indeed not specify a recursive option for grep. Also noted BSD grep man page says -r is deprecated in favour of -R. GNU and BSD grep support -R - are there still modern systems with a non-recursive grep? – grebneke Mar 4 '14 at 14:20
  • Note that BSD grep (except recent OpenBSD) is now a fork of an old version of GNU grep. With recent GNU grep, -r should be preferred over -R as it doesn't follow symlinks (BSD greps handle the symlink issues differently/better). The grep of most commercial Unices don't support -r. – Stéphane Chazelas Mar 4 '14 at 14:24
2
find . -name .svn -prune -o -path '*/trunk/*' -type f -exec grep pattern {} +
  • 1
    -exec **grep** pattern, no? – grebneke Mar 4 '14 at 13:34
  • @grebneke, oops, yes sorry. Fixed. – Stéphane Chazelas Mar 4 '14 at 13:57
  • This works, but I think the solution in the comment is more generic. The svn vas just an example, but I'll probably need this for other dirs too :) + the output is colored, which is awsome! :P – Alko Mar 4 '14 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.