Solved

Search for specific file content

Posted on 2014-09-15
7
380 Views
Last Modified: 2014-09-15
I would like to do a search to  list  all files that have a particular set of words contained in them, i.e., "digital brochures". I do not want it to be case sensitive.  I would like to do the search of all files in the current directory plus all its subdirectories.

Thank you.
0
Comment
Question by:geeta_m9
  • 3
  • 2
  • 2
7 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 400 total points
ID: 40323893
grep -R -i -l "digital brochures" .

Note the dot " ." at the end!

The above will list just filenames with matching content, not the content itself. To see the content along with the filename, omit "-l".
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40323906
Do you want the order specified as well like "digital brochures" or do you want all files that contain both words (anywhere in the file)?
0
 

Author Comment

by:geeta_m9
ID: 40323921
No, I want it in that order for this purpose. For academic purposes, let's say I wanted it the way you suggested. How would the command be modified?
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

Author Comment

by:geeta_m9
ID: 40323927
When I enter the command grep -R -i -l "digital brochures",  the cursor just seems to be stuck in one spot. Does this command take a long time to execute?
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 40323930
You forgot to type the dot "." at the end. See the note in my first comment!

To your academic question:

grep -E -R -i -l "digital|brochures" .

"-E" means "Interpret the pattern as an extended regular expression", and
the vertical bar ("pipe") means "or".
0
 
LVL 38

Assisted Solution

by:Gerwin Jansen, EE MVE
Gerwin Jansen, EE MVE earned 100 total points
ID: 40323944
>> Does this command take a long time to execute?
Depending on how much files you have, yes it can...

grep -iR -l "digital" . 2>/dev/null | xargs grep -iR -l "brochures" 2>/dev/null
0
 

Author Comment

by:geeta_m9
ID: 40323946
Yes, that was the problem. Thank you.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question