mona
December 9, 2005, 5:52am
1
Hi All,
I wanted to list all the files in the current directory which contains the pattern "error". I tried the following grep command
grep -i 'error' *.*
but i got the error message "ksh: /usr/bin/grep: 0403-027 The parameter list is too long."
Any idea why the grep didn't work?
Note: There are hundreds of files which contains this pattern.
I used find command to achieve the same result.
find . -type f -exec grep -i "error" {} \;
find . -type f -exec grep -i "error" /dev/null {} \;
The first command displays me the lines from all files which contains the pattern "error". But it doesn't append the filename in the front.
But the second command gave me the same result with directory name and filename appended in the beginning of each line?
Any idea why both the above find commands work differently?
vino
December 9, 2005, 6:24am
2
mona:
Hi All,
I wanted to list all the files in the current directory which contains the pattern "error". I tried the following grep command
grep -i 'error' *.*
but i got the error message "ksh: /usr/bin/grep: 0403-027 The parameter list is too long."
Any idea why the grep didn't work?
Note: There are hundreds of files which contains this pattern.
Not sure if the length makes a difference. You might want to see this post - Command line buffer limit? and Grep line length constraint problem - help!
The 2 find commands work differently as
the second passes 2 files to grep for
each invocation, in which case grep outputs
the filenames to distinguish. Yes it's a hack.
A better/more efficient option is to pass
as many filenames as possible to grep
to minimise the number of times it is invoked.
xargs is the tool you want for this:
find . -type f -print0 | xargs -r0 grep -F error
mona
December 11, 2005, 11:54pm
4
Thank you Vino and pixelbeat !!!