Doubt in find command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Doubt in find command
# 1  
Old 12-09-2005
Doubt in find command

Hi All,

I wanted to list all the files in the current directory which contains the pattern "error". I tried the following grep command

Code:
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.

Code:
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?
# 2  
Old 12-09-2005
Quote:
Originally Posted by 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

Code:
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!

Last edited by vino; 12-09-2005 at 07:30 AM..
# 3  
Old 12-09-2005
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
# 4  
Old 12-12-2005
Thank you Vino and pixelbeat !!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Mailx command doubt

hi all, I would need to add the description in the below syntax. let me know the below syntaxt how it can be changed to add the description in the below. ps -ef | grep "server" | mailx -s "servers currently which are running" operational@acel.com Server 62 -> Used for User acessing.... (14 Replies)
Discussion started by: arun888
14 Replies

2. UNIX for Dummies Questions & Answers

Doubt in ls command

dear users and experts, i am stuck withis command and i am unable to understand what is it doing?? ls -d * (7 Replies)
Discussion started by: seshank
7 Replies

3. Shell Programming and Scripting

Doubt in xargs command

Hi, What is the difference in capitalizing the option 'i' of xargs command, (i.e) xargs -i and xargs -I? Also, what is the difference between the below 2 commands? output_from_cmd | xargs -I {} grep '{}' file output_from_cmd | xargs -I grep '{}' file Any efficiency or performance... (4 Replies)
Discussion started by: royalibrahim
4 Replies

4. Shell Programming and Scripting

One doubt regarding chmod command

which one is correct chmod 777 file.txt or chmod 777 / file.txt what is difference in these two commands? thanx in advance (2 Replies)
Discussion started by: Himanshu_soni
2 Replies

5. Shell Programming and Scripting

sed command doubt

i have input files like this SFE_DOC_DATE (SFE_DOC_DATE:UniChar.:): "04/18/20" SFE_PSTNG_DATE (SFE_PSTNG_DATE:UniChar.:): "04/18/20" SFE_CREATEDON (SFE_CREATEDON:UniChar.:): "05/31/20" SFE_CLEAR_DATE (SFE_CLEAR_DATE:UniChar.:): "(NULL)" SFE_CLR_DOC_NO... (3 Replies)
Discussion started by: Gopal_Engg
3 Replies

6. UNIX for Dummies Questions & Answers

doubt in tar command

Hello sir, We can archive a file by :tar -cvf a.tar a.txt AND We can get it back by : tar -xvf a.tar I want to save the file extracted from a.tar into a specific location.How can I give the destination path in the above command ??? (2 Replies)
Discussion started by: nsharath
2 Replies

7. Shell Programming and Scripting

locate command doubt !!!

Hello, I want to search for a file/directory named "abc" which is located anywhere in the given unix system. I am using the command :- But the problem is that this is giving me all combinations of files with have 'abc' in their name. But can I know the option to be used to get the location... (5 Replies)
Discussion started by: nsharath
5 Replies

8. Shell Programming and Scripting

doubt in banner command !!!

hello, I am using banner command in my shell.I used :- The problem is that the output is printed in 3 separate lines.I want to display it in a single line.If the size is not enough then at least 2 words should come in the same line. Can you tell me what is the option in banner that would help... (4 Replies)
Discussion started by: nsharath
4 Replies

9. UNIX for Dummies Questions & Answers

doubt in tr command

Hi, I am trying to understand a script and found a line as follows: tr '\211\233\240' '\040' < $IN_FILE | tr -cd '\11\12\15\40-\176' > $TEMP_FILE Can any one explain the above line .. What are they trying to translate using the tr command.. I have not used tr command.. so feeling little bit... (2 Replies)
Discussion started by: risshanth
2 Replies

10. UNIX for Advanced & Expert Users

Doubt in SED command

PLEASE EXPLANIN ME... sed 's~\(.*\)\(<name>\)\(.*\)\(</name>\)\(.*\)~\2\3\4~' this is the format <start><name>123<\name><addr>BAC<\addr><loc>sfo<\loc></start> (1 Reply)
Discussion started by: gksenthilkumar
1 Replies
Login or Register to Ask a Question