Re: [LINUX:4086] grep

Murat Cakýr (mcakir@artemis.efes.net)
Mon, 03 Aug 1998 11:43:21 +0000


Burak Demircan wrote:
>
> grep i recursive olarak kullanabilecegim parametreyi bi turlu bulamadim
> boyle bisi grep icin mevcut degil mi eger oyleyse cozum ne olabilir
> sagolun

RECURSIVE GREP
Here is a nasty One-Liner:

Did you wish you could grep through files recursively
down subdirectories:

find . -type f -exec grep -l "foo" {} \\; -exec grep -n "foo" {} \\;
-exec echo " " \\;

Or another version that was submitted is:

find . -type f -print | xargs grep foo

Here is the command in script form.
This is probably easier in the long run....
=============== CUT HERE =======================================

# Script : gref
# Shell : any
# Author : Thom Vaught, David Miller
# Date : 8/16/90
#
# Recursively greps down a directory tree.
# If no path is specified, default is working directory.
#
# NOTE: Some shells require the variables in the "if"
# statements be quoted.

if [ $# = 1 ]
then
dir=.
else if [ $# = 2 ]
then
dir=$2
else
echo "Usage: `basename $0` pattern [path]"
exit 1
fi
fi

find $dir -type f -exec grep -l "$1" {} \\; \\
-exec grep -n "$1" {} \\; \\
-exec echo " " \\;

---
kolay gelsin
muratc.