find command fails mid-way during execution


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find command fails mid-way during execution
# 1  
Old 10-19-2016
Power find command fails mid-way during execution

I wish to search for a particular string say "Yellow_Colors" in all files in all folders in the current directory.

Below is the command I use:

Code:
find ./ -type f | xargs grep -i "Yello_Colors"

However, my command does not traverse all files and folders and errors out mid-way with the below error msg:

Code:
xargs: Missing quote: Your Claim Request Note_MS.pdf

Code:
uname -a
 SunOS mymac 5.10 Generic_150400-26 sun4v sparc sun4v

I understand that there are weird filenames in the directory, but I need my find command to complete execution and look for all files in the given directory.

Last edited by mohtashims; 10-19-2016 at 05:16 PM..
# 2  
Old 10-19-2016
I think Solaris 10/SunOS 5.10 comes with a version of find/xargs that groks the -print0/-0 directives, so you could try:
Code:
find ./ -type f -print0 | xargs -0 grep -i "Yello_Colors"

There is a possibility that this change will move the error from xargs to grep!

Andrew
# 3  
Old 10-19-2016
Try:
Code:
find . -type f -exec /usr/xpg4/bin/grep -i "Yello_Colors" /dev/null {} +

The /dev/null is there so the filename will also be printed if there is only one file in the directory and there is a match in it..


---
Quote:
Originally Posted by apmcd47
I think Solaris 10/SunOS 5.10 comes with a version of find/xargs that groks the -print0/-0 directives[..]
Unfortunately, this is not the case with standard version of find and xargs on Solaris. This is only available with GNU and BSD versions..

Last edited by Scrutinizer; 10-20-2016 at 02:16 AM..
This User Gave Thanks to Scrutinizer For This Post:
# 4  
Old 10-19-2016
Power

Quote:
Originally Posted by apmcd47
I think Solaris 10/SunOS 5.10 comes with a version of find/xargs that groks the -print0/-0 directives, so you could try:
Code:
find ./ -type f -print0 | xargs -0 grep -i "Yello_Colors"

There is a possibility that this change will move the error from xargs to grep!

Andrew
Code:
xargs: illegal option -- 0
find: bad option -print0xargs:
find: [-H | -L] path-list predicate-list
Usage: xargs: [-t] [-p] [-e[eofstr]] [-E eofstr] [-I replstr] [-i[replstr]] [-L #] [-l[#]] [-n # [-x]] [-s size] [cmd [args ...]]
bash-3.2$

# 5  
Old 10-19-2016
Just get rid of the xargs and invoke grep directly from find:
Code:
find . -type f -exec grep -i "Yello_Colors" {} +

Note to Scrutinizer: I don't think /usr/xpg4/bin/grep on Solaris 10 systems supports the -i option (but /usr/bin/grep does). And, since all of the filenames being passed to grep will start with ./, there is no need to use a /dev/null or -- operand to protect against filenames starting with a minus-sign being misinterpreted as options.
# 6  
Old 10-19-2016
Quote:
Originally Posted by Don Cragun
[..]
Note to Scrutinizer: I don't think /usr/xpg4/bin/grep on Solaris 10 systems supports the -i option (but /usr/bin/grep does).
Hi Don, I just had a look and it does support -i , but indeed /usr/bin/grep should work as well

Code:
SYNOPSIS
     /usr/bin/grep [-bchilnsvw] limited-regular-expression
          [filename]...

     /usr/xpg4/bin/grep [-E | -F] [-c | -l | -q] [-bhinsvx] -e pattern_list...
          [-f pattern_file]... [file]...

     /usr/xpg4/bin/grep [-E | -F] [-c | -l | -q] [-bhinsvx]
          [-e pattern_list]... -f pattern_file... [file]...

     /usr/xpg4/bin/grep [-E | -F] [-c | -l | -q] [-bhinsvx] pattern
          [file]...

This User Gave Thanks to Scrutinizer For This Post:
# 7  
Old 10-20-2016
The /dev/null makes sense in the case there is only one file in the directory tree. Or one more file than can be put into one argument list.
So yes the /dev/null should be there.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find command works on Linux but fails on Solaris.

Hi, I am looking for a generic find command that works on both Linux and Solaris. I have the below command that works fine on Linux but fails on solaris.find /web/config -type f '(' -name '*.txt' -or -name '*.xml' -name '*.pro' ')' Fails on SunOS mysolaris 5.10 Generic_150400-61 sun4v sparc... (1 Reply)
Discussion started by: mohtashims
1 Replies

2. Shell Programming and Scripting

Script execution fails

hi, i am trying to run this script, getting below error, can some one help me in this Error: -bash: on_failure.sh: line 23: syntax error: unexpected end of file ======================================================== # CHANGE HISTORY # # YYYYMMDD Change by Desription # --------... (2 Replies)
Discussion started by: szs
2 Replies

3. Shell Programming and Scripting

Script to check one command and if it fails moves to other command

Input is list of Server's, script is basically to remove old_rootvg, So it should check first command "alt_rootvg_op -X old_rootvg" if it passes move to next server and starts check and if it fails moves to other command "exportvg old_rootvg" for only that particular server. I came up with below,... (6 Replies)
Discussion started by: aix_admin_007
6 Replies

4. UNIX for Dummies Questions & Answers

Find command fails when a space is in the directory path variable

I have a script like this running under OS X 10.8. The problem arises when the find command encounters a space in the path name. I need the "dir" variable as I'll be extending the script to more general use. #!/bin/bash CFS=$IFS IFS=$(echo) set dir = "/Users/apta/Library/Mail\... (3 Replies)
Discussion started by: apta
3 Replies

5. Shell Programming and Scripting

SH script, variable built command fails, but works at command line

I am working with a sh script on a solaris 9 zone (sol 10 host) that grabs information to build the configuration command line. the variables Build64, SSLopt, CONFIGopt, and CC are populated in the script. the script includes CC=`which gcc` CONFIGopt=' --prefix=/ --exec-prefix=/usr... (8 Replies)
Discussion started by: oly_r
8 Replies

6. Shell Programming and Scripting

Stop execution of script if some condition fails

After my if condtion give rusult true then script should stop execution. Please advice...Thnaks in advance (1 Reply)
Discussion started by: vivek1489
1 Replies

7. Shell Programming and Scripting

Need help! command working ok when executed in command line, but fails when run inside a script!

Hi everyone, when executing this command in unix: echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csvIt works fine, but running this command in a shell script gives an error saying that there's a syntax error. here is content of my script: tdbsrvr$ vi hc.sh "hc.sh" 22 lines, 509... (4 Replies)
Discussion started by: 4dirk1
4 Replies

8. AIX

Find command fails in crontab

Hi , I imported find command I have on my hp-ux server to clean up the /tmp of my new IBM AIX servers. Though, the commands always fails in the cron but if I past it at the prompt, it works find. I tried with at jobs and regular 'find' . Could anyone tell me what I am doing wrong? Many... (4 Replies)
Discussion started by: cforget2810
4 Replies

9. Programming

Linux: dlopen fails to find symbols

I've attached a tar.gz containing three tests to demonstrate the problem I'm having. Within the tar are two shared libraries, two test applications, and a Makefile that builds the three tests. The shared libaries are libshlib1.so and libshlib2.so. Both export a function, libFunc, which takes... (5 Replies)
Discussion started by: DreamWarrior
5 Replies

10. Shell Programming and Scripting

Scripts fails if you change its code during the execution.

So a script is working properly (tested many times) , then you add a new fine piece of code ,finaly its fails generally with a syntax error at the last line of the script. :confused:... does anybody why this happens? >uname -a HP-UX test... (4 Replies)
Discussion started by: Klashxx
4 Replies
Login or Register to Ask a Question