Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grep "too many arguments" ---- you want an argument do you!?!

Status
Not open for further replies.

Tracy3e

Technical User
Jun 23, 2001
54
CA
grep is so annoying when it says "argument list too long". This happens quite often when searching our large directories.

grep -i srchparam *1f* <---- too many arguments
grep -i srchparam *1fL* <---- too many arguments
grep -i srchparam *1fLA* <---- too many arguments
grep -i srchparam *1fLAA* <---- too many arguments
grep -i srchparam *1fLAA0* <---you have to be this specific for the command to work which could take forever depending on the different filename combinations you have to search on

I thought I'd ask if there was a grep switch that would get me around this limitation.

Please & Thank you!
 
Tracy:

Unfortunately, I don't have a system that fails, but won't xargs help you with this:

ls *1f*|xargs grep -i otherstuff

Regards,

Ed
Schaefer
 
Hi Ed, I hadn't heard of xargs so I tried the command you gave me but still too long.

ls *1f* |xargs grep -i smith
bash: /bin/ls: Argument list too long

There are 11,000+ files in this particular directory which is typical of the directories we have to search.
 
That's because the ls is expanding the arguments.

You need to do this:

find . -name '*1f*' | xargs grep -i smith

The problem is not ls or grep: it's the shell and it's environment space. Using the find avoids the problem.

If you want the NAMES of the files that have &quot;smith&quot;, do it like this:

find . -name '*1f*' | xargs grep -i smith /dev/null

(the /dev/null just forces the print of the file name in the case where grep only sees one arg from find) Tony Lawrence
SCO Unix/Linux Resources tony@pcunix.com
 

It works! It works!!

You don't know how many people you've made happy today :)

I love these tek-tips forums.
 
Doesn't take a lot to make your day does it ?

:)

Glad you solved your problem. No go forth and help someone else- pay it forward!
Tony Lawrence
SCO Unix/Linux Resources tony@pcunix.com
 
ha, true ;-)

Just makes me wish I had asked a long time ago.....

 
Well, that's a good general point.

I'm always surprised to hear from customers that they'd like to do X but either somebody told them it couldn't be done or they just assumed it. &quot;X&quot; can just about *always* be done- it may cost y times 112, or it may cost very little, but it is very seldom that it really cannot be done.

These forums are a good place to air your annoyances. You may just have missed some important piece of information that can give you another happy day.

I browse a lot of newgroups and pick up a lot of good stuff, but another thing I do pretty regularly is re-read man pages and books I've already read. Regularly I find some little gem that I previously missed, had forgotten, or had misunderstood entirely.

For example, I probably read the Perl Camel book two or three times a year. I was thumbing through part of it this morning while waiting for a meeting, and came across something I have misunderstood for years! Apparently every time I read it before I either missed this or maybe I just didn't have enough base knowledge to grasp it then- I find that's often the reason.

Anyway, I'm a-rambling :)

Tony Lawrence
SCO Unix/Linux Resources tony@pcunix.com
 
so...what you are saying is that you are a true-blue techno-geek (said in the nicest, most respectful way of course) who likes to read tech manuals in his spare time.

This, I had already guessed ;-)

I have a post in the ODBC forum that no one ever answers.....if you think you could possibly help me with that one I'll send it to you (unless you can easily find it on clicking on my name).
 
I dunno a thing about ODBC, sorry.


Bruce Garlock posts in some of these forums and I know he has some ODBC thingies running.. maybe he'll notice this..


Tony Lawrence
SCO Unix/Linux Resources tony@pcunix.com
 
If you want to avoid &quot;find&quot; and the search in the subdirectories, you might try this:
Code:
echo *1f* | xargs grep ...
In this case, don't use quotes because we want to expand *1f*.
I tested this on HP-UX10.20 with ksh and sh. It's amazing to see how sh provides faster results.
 
Thank you, that command works too.

You don't know anything about ODBC, do you? ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top