Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-31-2013
Registered User
 
Join Date: Jun 2011
Posts: 6
Thanks: 3
Thanked 0 Times in 0 Posts
Arg list too long

Hello All,
I am trying to find a file name with .sh exention from a list of .dat files inside a directory.

find /app/folder1/* -name '*.dat'| xargs grep '.sh'
ksh: /usr/local/bin/find: arg list too long

Please help me finding the command.

Thanks

Sponsored Links
    #2  
Old 01-31-2013
Yoda's Avatar
Jedi Master
 
Join Date: Jan 2012
Location: Galactic Empire
Posts: 2,510
Thanks: 167
Thanked 816 Times in 785 Posts
Try running:

Code:
find /app/folder1/* -name '*.dat' -type f -exec grep '.sh' {} \;

Sponsored Links
    #3  
Old 01-31-2013
Registered User
 
Join Date: Jun 2011
Posts: 6
Thanks: 3
Thanked 0 Times in 0 Posts
Thanks - but that does not work either.
Maybe the ncargs value is too low on my system.

ncargs 6 ARG/ENV list size in 4K byte blocks True
    #4  
Old 01-31-2013
Moderator
 
Join Date: Jul 2012
Location: San Jose, CA, USA
Posts: 1,672
Thanks: 72
Thanked 603 Times in 527 Posts
I assume that bipinajith's proposed solution will still fail because /app/folder1/* is expanding to a list of arguments too long to process. The following should avoid that problem and be MUCH more efficient:

Code:
find /app/folder1 -name '*.dat' -type f -exec grep '.sh' {} +

Note, however, that if your .dat files are binary files (rather than text files) grep might not work. (The standards only specify the behavior of grep when its input files are text files.)

Also note that if grep is called with only one file operand, the name of the file in which the line is found will not be printed; just the contents of the matching line. If your .dat files are text files and you want the name of the file to be printed as well as the matched lines even if there is only one file operand, add /dev/null as another file operand. If you only want the names of matching files, but don't need to see the matched lines use the -l (letter ell; not digit 1) option.

And note that the pattern specified by '.sh' is a basic regular expression will match the two characters sh as long as they are not the 1st two characters on a line. If you want to match the three characters .sh , you need to add the -F option, use the obsolescent fgrep utility instead of grep, or escape the period in the BRE.
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
arg list too long Zenwork Shell Programming and Scripting 2 10-08-2008 03:06 PM
ls -t arg list too long CSU_Ram UNIX for Dummies Questions & Answers 4 05-05-2005 10:19 AM
arg list too long encrypted UNIX for Advanced & Expert Users 8 11-12-2004 05:38 AM
egrep and Arg list too long kingo UNIX for Dummies Questions & Answers 6 05-22-2002 11:52 AM
arg list too long vingupta UNIX for Dummies Questions & Answers 5 08-02-2001 11:43 PM



All times are GMT -4. The time now is 05:36 PM.