* Re: Searching for text in a file
@ 2001-05-29 20:54 Bob Harris
0 siblings, 0 replies; 5+ messages in thread
From: Bob Harris @ 2001-05-29 20:54 UTC (permalink / raw)
[[ This message was both posted and mailed: see
the "To," "Cc," and "Newsgroups" headers for details. ]]
In article <3b13fcaa@nubby2.>, Aaron Banks <banks45@yahoo.com> wrote:
X This may be simple. I want to search for a certain text string in all files
X on my system. How do I do that?
write a simple script:
#!/bin/ksh
find starting_directory -type f -print | while read file
do
if grep -q "search string" $file
then
echo $file
fi
done
Modify the script as needed. This script will start searching in
whatever directory you substitue for 'starting_directory', and will
grep each regular file looking for "search string" as specified by you.
If it finds a file that includes the string, it will display the name
of the file where it was found.
Bob Harris
^ permalink raw reply [flat|nested] 5+ messages in thread[parent not found: <3b13fcaa@nubby2.>]
* Re: Searching for text in a file [not found] <3b13fcaa@nubby2.> @ 2001-05-29 20:38 ` Stuart R. Fuller 2001-05-30 17:22 ` Mario Stargard 2001-05-29 20:38 ` Stuart R. Fuller 2001-05-30 6:24 ` Michael Heiming 2 siblings, 1 reply; 5+ messages in thread From: Stuart R. Fuller @ 2001-05-29 20:38 UTC (permalink / raw) Aaron Banks <banks45@yahoo.com> wrote: : This may be simple. I want to search for a certain text string in all files : on my system. How do I do that? find / | xargs grep my-string Stu ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Searching for text in a file 2001-05-29 20:38 ` Stuart R. Fuller @ 2001-05-30 17:22 ` Mario Stargard 0 siblings, 0 replies; 5+ messages in thread From: Mario Stargard @ 2001-05-30 17:22 UTC (permalink / raw) "Stuart R. Fuller" wrote: > > Aaron Banks <banks45@yahoo.com> wrote: > : This may be simple. I want to search for a certain text string in all files > : on my system. How do I do that? > > find / | xargs grep my-string > > Stu You've not guaranteed that grep will get more than one argument and so won't return the filename in some instances. Also you can really speed things up by just looking in text files. grepping through binaries, especially oracle dbf's can be time consuming. find . -type f |xargs file |awk -F: '$NF ~ /text/{ print $1 }' |xargs grep my-string /dev/null Mario ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Searching for text in a file [not found] <3b13fcaa@nubby2.> 2001-05-29 20:38 ` Stuart R. Fuller @ 2001-05-29 20:38 ` Stuart R. Fuller 2001-05-30 6:24 ` Michael Heiming 2 siblings, 0 replies; 5+ messages in thread From: Stuart R. Fuller @ 2001-05-29 20:38 UTC (permalink / raw) Aaron Banks <banks45@yahoo.com> wrote: : This may be simple. I want to search for a certain text string in all files : on my system. How do I do that? Better yet: find / -type f | xargs grep my-string Stu ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Searching for text in a file [not found] <3b13fcaa@nubby2.> 2001-05-29 20:38 ` Stuart R. Fuller 2001-05-29 20:38 ` Stuart R. Fuller @ 2001-05-30 6:24 ` Michael Heiming 2 siblings, 0 replies; 5+ messages in thread From: Michael Heiming @ 2001-05-30 6:24 UTC (permalink / raw) Aaron Banks wrote: > > This may be simple. I want to search for a certain text string in all files > on my system. How do I do that? Hello, using ksh: #!/bin/ksh # grep -r with ksh # michael@heiming.de - 2001-04-08 # usage: rgrep <search_for> <search_path> SW=${1} SP=${2} if [ $# -ne 2 ] then echo "usage: rgrep <search_for> <search_path>" exit 1 fi find $SP -type f -exec grep $SW {} /dev/null \; Good luck Michael Heiming ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2001-05-30 17:22 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-05-29 20:54 Searching for text in a file Bob Harris
[not found] <3b13fcaa@nubby2.>
2001-05-29 20:38 ` Stuart R. Fuller
2001-05-30 17:22 ` Mario Stargard
2001-05-29 20:38 ` Stuart R. Fuller
2001-05-30 6:24 ` Michael Heiming
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox