I want to create a script that could find a certain text string (a name) in most files through an entire directory including the subfolders. Is that possible?
I am running this on Solaris 8, and if I have asked this in the wrong topic area, please let me know.
Thanks.
Try this:
find . type f -exec basename {} \;
vino
August 23, 2006, 9:24am
3
kjbaumann:
I want to create a script that could find a certain text string (a name) in most files through an entire directory including the subfolders. Is that possible?
I am running this on Solaris 8, and if I have asked this in the wrong topic area, please let me know.
Thanks.
find /dir/to/search -type f -exec grep "search string" {} /dev/null \;
Yeah right, Vino's script does what OP has asked, I just rushed into reply without properly reading the query.
reborg
August 23, 2006, 9:41am
5
Also
find /dir/to/search -type f | xargs grep "search string"
Thanks all. Worked as needed.
What's the /dev/null bit for? I've used find a lot and not seen that before. What do you know that I don't?
That is a virtual file that can be written to. It will print the output onto your screen. The data written to this file gets discarded.
reborg
August 23, 2006, 7:01pm
9
It used to fool grep into listing the filename where a match occurs, instead of just the matching line. However you will never get a match from /dev/null
try:
grep `hostname` /etc/hosts
then
grep `hostname` /etc/hosts /dev/null
And you'll see what I mean.
Oh I see now, useful to know thanks.
Hi Reborg,
i too tried ur commands but can you just tell me why we need that single quote .. it has not worked without those..
-Chanakya
with the command `hostname` you are searching for the output of the command hostname in the /etc/hosts and /dev/null...
note the back tilts - command executed and the output is used
say if the node name is unixcom
much similiar to searching like
>hostname
unixcom
>grep unixcom /etc/hosts /dev/null
Thanks Madan now i got it..