Does anyone have a solution for arg list too long error.
I have got this from the web but I fail to make any sense out of it
Thanks
enc
Does anyone have a solution for arg list too long error.
I have got this from the web but I fail to make any sense out of it
Thanks
enc
Check out the xargs command. Can you post the command that is failing?
I have a dirctory(in fact many directories) for which I have to grep
a certain string -In my case a 10 digit number starting with 011
code:
For directories having a lot many files it says
/usr/bin/grep Arg list too long
Would find command help me?
find . -name * -exec egrep '^011......$' /dev/null {} \;
Thanks
enc
I think the find syntax as you have it will have the same problem. If you use xargs like this you may have some luck. I am not anywhere I can test it right now to confirm for you but this syntax may work:
find ./ -print | xargs grep '^011.......$' *| cut -f1 -d :
If you run this from your top level directory where you were running your script, you should get the results you want.
Gives the output while searching in a single directory:
xargs: a single arg was greater than max argsize of 2048 characters
Any Ideas??
enc
Drop the "*" from the grep,
find ./ -print | xargs grep -l '^011.......$'
You also won't need the cut, use -l (ell) to grep to print the matching filenames.
Cheers
ZB
Thanks jazzybob you saved my day!!
But I was wondering why
find ./ -print | xargs grep '^011.......$' *| cut -f1 -d :
did not work in the first place.
Chill
enc
You could certainly leave the "cut" in the pipe (and discard the -l to grep), but it's an uneccessary process, so it may aswell be dropped.
The main problem with the original command was the "*" wildcard in the grep, this was expanding to a list of all the files in the current directory (as it would do if you run an "echo *" at the prompt), and thusly overflowing xargs. Seeing as you're already feeding a list of files in from the find, the specification of files within the grep command itself is not needed.
Cheers
ZB
I can't see why you still have * in the command if you have the xargs.
find ./ -type f -print | xargs grep '^011.......$' | cut -f1 -d :
:). Hope this helps.