Solved

how to search a file which contain ....

Posted on 1998-12-29
5
228 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Parsing a file using ksh 10 79
Can I delete authorized_keys in FreeBSD 1 119
Doing a DR (Disaster Recovery) Test on Red Hat Linux Servers. 2 149
How to clone solaris 10 machine 33 190
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

738 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