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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
02-27-2007, 11:05 AM
|
#1
|
LQ Newbie
Registered: Feb 2007
Posts: 2
Rep:
|
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!
|
|
|
02-27-2007, 11:25 AM
|
#2
|
LQ Newbie
Registered: Feb 2007
Posts: 29
Rep:
|
Try:
Code:
find . -name "*.html" -type f -print -exec grep -ls 'string' {} \;
Not on linux at the moment, so cant confirm myself.
|
|
|
02-27-2007, 11:35 AM
|
#3
|
LQ Newbie
Registered: Feb 2007
Posts: 2
Original Poster
Rep:
|
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.
|
|
|
02-27-2007, 12:36 PM
|
#4
|
LQ Newbie
Registered: Feb 2007
Distribution: mostly Debian
Posts: 14
Rep:
|
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.
|
|
|
02-27-2007, 06:03 PM
|
#5
|
Member
Registered: Dec 2003
Location: Toronto, Canada
Distribution: Mint, Mandriva
Posts: 221
Rep:
|
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'
|
|
|
02-27-2007, 06:29 PM
|
#6
|
Senior Member
Registered: Jan 2003
Posts: 2,786
|
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.
|
|
|
All times are GMT -5. The time now is 07:49 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|