How to find files containing specific text ?
How do I combine "find" -name looking for specific "pattern" using grep?
For example find . -name "*177.cpp" | grep "FAILED" finds nothing. I know such files exists , so I must be using wrong syntax. ( Admitting user error should help to eliminate inquisitive "replies' ) Help would be appreciated. |
Why do you expect the response to include the string "FAILED"?
First, try your find command without piping to grep and see what happens. |
If you are trying to search the file names then this will do it:
Code:
find . -type f -name "*177.cpp" -print | grep "FAILED" Code:
man find Code:
find . -type f -name "*177.cpp" -exec grep "FAILED" {} + |
Another option would be to use xargs
Code:
find . -type f -name "*177.cpp" -print0 | xargs -0 grep "FAILED" |
I read on xargs a few days ago, xargs vs -exec .. xarg was said to be faster, so if you got lots of like files...
|
or probably grep -r FAILED would be sufficient
|
Quote:
Code:
find . -name "*177.cpp" -exec grep FAILED {} \; |
Quote:
find . -type f -name "*.cpp" -exec grep "DEFINE" {} + Example I need to find "#DEFINE MISO *" in header files. Please - no references to RTFM necessary , I asked for help in forum . I am perfectly capable to read and "try this ... try that". I am asking for actual solution, if possible. I understand there are different ways to do this , but I wanted HELP on "find" and "grep". |
Code:
|
What is wrong with
Code:
find . -type f -name "*.cpp" -exec grep "DEFINE" {} + Do you want to also search in *.h files? Code:
find . -type f \( -name "*.cpp" -o -name "*.h" \) -exec grep "DEFINE" {} + the ( ) grouping is needed because the default AND between find options has precedence over the -o OR. The \( \) or "(" ")" escapes are needed to prevent the shell's interference. History: early GNU find had only -exec ... {} \; that was much slower than -print0 | xargs -0 ... with programs that take multiple arguments. The -exec ... {} + comes from the Posix standard, works like the xargs, and should be even faster. |
Sorry but I don't understand your need. First you wrote your initial post in such a way we thought you were searching for pattern "FAILED"... and now you seem to search for "#DEFINE MISO"...
Quote:
Edit: OK, regarding the command, MadeInGermany got it first ;) |
Quote:
Anyway, MadeInGermany has provided you with a modified solution in post #10. If it is not what you are looking for then please be more specific in the details of your problem and its scope. |
Quote:
I wanted to find "DEFINE" not "DEFINES". PHP Code:
|
Quote:
Code:
man grep So, Code:
... -exec grep "\bDEFINE\b" {} + ... |
Quote:
but i don't want that stupid cigar anyhow. this thread is a fine example of how some people mistreat anyone who doesn't provide a spelled out perfect solution to a problem they haven't even defined properly. |
All times are GMT -5. The time now is 08:00 PM. |