LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-27-2007, 11:05 AM   #1
mellowjen
LQ Newbie
 
Registered: Feb 2007
Posts: 2

Rep: Reputation: 0
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!
 
Old 02-27-2007, 11:25 AM   #2
tread
LQ Newbie
 
Registered: Feb 2007
Posts: 29

Rep: Reputation: 15
Try:

Code:
find . -name "*.html" -type f -print -exec grep -ls 'string' {} \;
Not on linux at the moment, so cant confirm myself.
 
Old 02-27-2007, 11:35 AM   #3
mellowjen
LQ Newbie
 
Registered: Feb 2007
Posts: 2

Original Poster
Rep: Reputation: 0
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.
 
Old 02-27-2007, 12:36 PM   #4
jr1
LQ Newbie
 
Registered: Feb 2007
Distribution: mostly Debian
Posts: 14

Rep: Reputation: 0
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.
 
Old 02-27-2007, 06:03 PM   #5
cfaj
Member
 
Registered: Dec 2003
Location: Toronto, Canada
Distribution: Mint, Mandriva
Posts: 221

Rep: Reputation: 31
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'
 
Old 02-27-2007, 06:29 PM   #6
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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).

Last edited by Dark_Helmet; 02-27-2007 at 06:49 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
xargs: unmatched single quote akudewan Linux - Newbie 5 07-28-2014 01:16 PM
xargs multiple ./{} usage sadarax Linux - General 1 02-23-2006 09:51 PM
xargs and my own script harmster Linux - Software 4 05-07-2005 11:35 AM
xargs question reitzell Linux - Newbie 4 07-04-2004 03:36 AM
xargs: unmatched single quote fillatre Linux - Software 2 06-05-2004 11:04 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration