Advertisement

05.21.2008 at 06:50AM PDT, ID: 23420778
[x]
Attachment Details

How do you get grep to do a file specific recursive search if ...

Asked by fklein23 in Linux, Linux Programming

Tags: Open Source, Linux, ANY, grep regular expression question

This has always bugged me. If I want to do a recursive search on all files of a specific type (like *.c*, for instance)?


This works:
 grep -R 2.04.0 * |grep VERSION

but it takes forever, because the directories rooted here contain large binary files, and many other files than the *.c files which take a long time to traverse.

This just doesn't work, but says (to me, anyway) exactly what I want to do: search all the *.c files rooted at the current directory for files with the word VERSION and a number that looks like 2.04x0 for any digit x.

grep -R 2.04.0 *.c | grep VERSION

It will find all the *.c files that meet the criterion in the current directory, but it doesn't recurse, in spite of the "-R" option.

I have tried every variation I can think of and just can't find the right combination.

This same issue of not being able to recurse on specific file types has always bugged me about Linux and Unix, not just for grep, but for ls as well.

It just seems to me that there must be something wrong either with the recursive parsing facility of Linux/Unix (or more likely my understanding of it!) :-)

Start Free Trial
 
Loading Advertisement...
 
[+][-]05.21.2008 at 07:14AM PDT, ID: 21615228

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]05.21.2008 at 07:37AM PDT, ID: 21615519

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.21.2008 at 07:44AM PDT, ID: 21615602

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Linux, Linux Programming
Tags: Open Source, Linux, ANY, grep regular expression question
Sign Up Now!
Solution Provided By: guitarist5377
Participating Experts: 2
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628