How to use grep command recursively?
grep -r pattern . doesn’t work.
How to use grep command recursively?
grep -r pattern . doesn’t work.
JalajaDevi <jganapat@storage.com> wrote:
How to use grep command recursively?
grep -r pattern . doesn’t work.
Use find to do the recursion.
e.g.
QNX Training Services
dagibbs@qnx.com
We have used wild cards for directory names, such as:
grep -i pattern /.c
David Gibbs wrote:
JalajaDevi <> jganapat@storage.com> > wrote:
How to use grep command recursively?grep -r pattern . doesn’t work.
Use find to do the recursion.
e.g.
find . -name ‘*.c’ | xargs grep -i pattern | less
–
QNX Training Services
dagibbs@qnx.com
–
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
/ \ | __ ) | ~Jeffrey Jordan jordanj@abc-naco.com
/ | \ | _ ( Phone: (610)630-2330x216 jljordan@wans.net
/ ++ \ | ) ( Fax: (610)630-2323
|| |||/_| 2550 Blvd. o/t Generals, Norristown PA 19403
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Jeffrey O L Jordan <jljordan@wans.net> wrote:
We have used wild cards for directory names, such as:
grep -i pattern /.c
There are limits to this – in particular it isn’t very efficient
if you want to drop more than a directory level or so, and if you
are trying to deal with a lot of files, it can blow your command-line
length limitations. (The shell has a fixed length for the command-line
buffer, and the /.c expansion is done by the shell. I think the
maximum is 255 characters in QNX4.)
QNX Training Services
dagibbs@qnx.com
David Gibbs <dagibbs@qnx.com> wrote:
Jeffrey O L Jordan <> jljordan@wans.net> > wrote:
We have used wild cards for directory names, such as:grep -i pattern /.c
(The shell has a fixed length for the command-line
buffer, and the /.c expansion is done by the shell. I think the
maximum is 255 characters in QNX4.)
Looks like I’ve been doing this for too long. The fixed limit is much
longer than 255 characters. Not sure how long, but over 60K.
QNX Training Services
dagibbs@qnx.com
try
find . -name “*.c” -exec grep YOUR_PATTERN {} ; -print
“JalajaDevi” <jganapat@storage.com> wrote in message
news:9krgeg$llq$1@inn.qnx.com…
How to use grep command recursively?
grep -r pattern . doesn’t work.
I would usually put the -print in front of the -exec. i.e.
find . -name “*.c” -print -exec grep YOUR_PATTERN {}
Bill Caroselli
“James Carmody” <carmodyj@aecl.ca> wrote in message
news:9l0r74$aaj$1@nntp.qnx.com…
try
find . -name “*.c” -exec grep YOUR_PATTERN {} ; -print
“JalajaDevi” <> jganapat@storage.com> > wrote in message
news:9krgeg$llq$> 1@inn.qnx.com> …
How to use grep command recursively?grep -r pattern . doesn’t work.
\
“Bill Caroselli (Q-TPS)” <qtps@earthlink.net> wrote:
I would usually put the -print in front of the -exec. i.e.
find . -name “*.c” -print -exec grep YOUR_PATTERN {}
Bill Caroselli
This is slower than the xargs solution I suggested:
find . -name ‘*.c’ | xargs grep -i pattern | less
The reason being that your example will load & run grep for each
file, my example will only run grep for a collection of files.
Also, grep will put the filename in its output if it has multiple
files on its command line argument, making it easier to determine
which file(s) has(ve) the string.
QNX Training Services
dagibbs@qnx.com
JalajaDevi <jganapat@storage.com> wrote:
: How to use grep command recursively?
: grep -r pattern . doesn’t work.
alain