[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

how to search a file which contain ....

Posted on 1998-12-29
5
Medium Priority
?
233 Views
Last Modified: 2010-08-05
how can I search a file and display a filename where
these files contain the "string"
I know that I can use "grep" to find but how to advance the searching included the sub-directory
thank
0
Comment
Question by:chsoh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 4

Accepted Solution

by:
jos010697 earned 0 total points
ID: 2008578
Something like this could do the job for you:

   grep -l string `ls -R`

(note: the quotes around the ls command are back quotes).

kind regards,

Jos aka jos@and.nl

0
 

Author Comment

by:chsoh
ID: 2008579
I think is better if `ls -R` is change to `find *`

0
 
LVL 4

Expert Comment

by:jos010697
ID: 2008580
Yes, although I don't know about the 'better' part, but find can do the job too:

find . -name '*' -exec grep -l string {} ';'

kind regards,

Jos aka jos@and.nl

ps. All those silly quotes _are_ necessary here ...
0
 

Expert Comment

by:rajeevm
ID: 2008581
Hello ,
If you want to search recursively , can you please try below given shell script.
#!/usr/bin/ksh

if [[ $# -eq 0 ]]
then
   echo "Usage $0 Pattern"
   return 1
fi

Pattern=$*

echo "Please wait : Extracting  directory names ...\c"

Dirs=$(find . -type d -print)

echo "done."

for dir in $Dirs
do
  grep -in $Pattern $dir/*
done

return 0                
0
 

Expert Comment

by:rajanxyz
ID: 2008582
The correct answer would be:

find . -type f -exec grep -l "string" \{\} \;

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

649 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