LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Xargs: Missing quote (http://www.linuxquestions.org/questions/programming-9/xargs-missing-quote-532939/)

mellowjen 02-27-2007 10:05 AM

Xargs: Missing quote
 
Hello,

I'm trying to run this program:

find . -name "*.html" -type f | xargs grep -ls 'string'

but it crashes with the error:
xargs: Missing quote: (filename)

The file name has a single quote in it (which is ridiculous but that's another topic altogether).

Is there any way to get around this? Essentially, I am trying to search an entire directory and all it's files and subfolders that include a certain string all the while suppressing an errors.

Thanks!

tread 02-27-2007 10:25 AM

Try:

Code:

find . -name "*.html" -type f -print -exec grep -ls 'string' {} \;
Not on linux at the moment, so cant confirm myself.

mellowjen 02-27-2007 10:35 AM

Quote:

Originally Posted by tread
Try:

Code:

find . -name "*.html" -type f -print -exec grep -ls 'string' {} \;
Not on linux at the moment, so cant confirm myself.

Thanks for your reply but it seems that this is listing every .html file within the directory but not searching for "string" within those files. But no errors.

jr1 02-27-2007 11:36 AM

Quote:

Originally Posted by mellowjen
Thanks for your reply but it seems that this is listing every .html file within the directory but not searching for "string" within those files. But no errors.

The example tread gave should be grep'ing in each .html file, but it also lists the name of every .html that is found, which you probably don't want. Each matching file will be listed twice in the output (once each by find and grep), and each non-matching file will be listed once (by find). I'd suggest getting rid of find's -print option.

cfaj 02-27-2007 05:03 PM

Quote:

Originally Posted by mellowjen
Hello,

I'm trying to run this program:

find . -name "*.html" -type f | xargs grep -ls 'string'

but it crashes with the error:
xargs: Missing quote: (filename)

The file name has a single quote in it (which is ridiculous but that's another topic altogether).

Is there any way to get around this? Essentially, I am trying to search an entire directory and all it's files and subfolders that include a certain string all the while suppressing an errors.

Thanks!

Use NUL to terminate file names:

Code:

find . -name "*.html" -type f -print0 | xargs -0 grep -ls 'string'

Dark_Helmet 02-27-2007 05:29 PM

This worked fine on my system:
Code:

find . -name "*.html" -type f -printf '"%p"\n' | xargs grep -ls 'string'
EDIT:
That command assumes none of your files have a double quote in them. If you do, then you'll run into similar problems as you did originally (mismatched quotes).


All times are GMT -5. The time now is 10:33 AM.