grep : Argument list too long

Hi,

i am having some trouble with the below command, can some one suggest me the better way to do it.

grep -l 'ReturnCode=1' `find $Log -newer /tmp/Failed.tmp -print | xargs ls -ld | egrep SUB | egrep -ve 'MTP' -ve 'ABC' -ve 'DEF' -ve 'JKL' -ve 'XYZ' | awk '{print $9}'` > $Home1

Its giving grep: Argument list too long

Thanks in advance:b:

Please post what Operating System and version you are running and what Shell you use.

Also, please explain what the script is intended to do and provide sample input and sample expected output data. It is not possible to guess from the code provided whether you are searching the names of files or the content of files (or some combination of both)?

I'm not sure exactly when I've seen such a rubbish piece of code :slight_smile: You are passing each element of that convoluted find command as a filename to grep. That's where the error is coming from - there are just too many filenames to pass as arguments.

Here's my take, which might also be a mis-interpretation of your intentions:

rm -f $Home1
find $Log -newer /tmp/Failed.tmp -name "*SUB*" | egrep -v 'MTP|ABC|DEF|JKL|XYZ' | while read FILE; do
  grep -l "ReturnCode=1" "$FILE" >> $Home1
done