LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-12-2005, 05:13 AM   #1
akudewan
Member
 
Registered: Apr 2004
Location: India
Distribution: Ubuntu
Posts: 364

Rep: Reputation: 31
Question xargs: unmatched single quote


I was learning some shell commands in a little more detail when I came across this situation:

I made a file by the name of foo, by giving this command. (pwd is /home/akudewan/files/)

Code:
$cat > foo.txt
This is a TEXT file
^D
Now, combining the "find" and "grep" command, I will search for the words "TEXT" in my ~/files directory.

So, I did:

Code:
$find /home/akudewan/files -type f | xargs grep TEXT
xargs: unmatched single quote
I got the above error, and I got confused.

I made a subdirectory and did a "cd" to ~/files/temp/. Then I copied foo.txt here and also made another file "file.txt" I changed the command to:

Code:
$find /home/akudewan/files/temp -type f | xargs grep TEXT
/home/akudewan/files/temp/foo:TEXT
As you can see, it worked. I tried the command again in the parent directory, but got the same error. I checked the permissions, no problem with them. So why is this happening? And what does the error mean?
 
Old 02-12-2005, 07:18 AM   #2
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
Hi.

My best guess is that the output of find contains a single quote.
One remedy for this could be:
$ find -type f | grep -ve "'" | xargs ...

perhaps you could post the output of these commands:

$ find
$ find --version
$ grep --version
$ xargs --version

-- Jonas

PS. "pwd is /home/akudewan/files/" is _slightly_ incorret: pwd is an abbreviation for 'print [current] working directory', whereas cwd is 'current working directory' (or something to that effect). Thus, it would have been more correct to say "cwd is /home/akudewan/files". I hope you don't think of this as criticism, I'm just trying to enlighten you
 
Old 02-13-2005, 01:02 AM   #3
akudewan
Member
 
Registered: Apr 2004
Location: India
Distribution: Ubuntu
Posts: 364

Original Poster
Rep: Reputation: 31
Thanks jonaskoelker. There was a file that had a single quote (bruce lee's jeet kune do.pdf)

I renamed that file and the command worked perfectly. But how do I go about it if there is a quote?

Code:
$ find --version
GNU find version 4.1.7
$ grep --version
grep (GNU grep) 2.5

Copyright 1988, 1992-1999, 2000, 2001 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ xargs --version
GNU xargs version 4.1.7
PS: thanks for correnting me about the pwd thing. (I thought it was "Present" working directory)
 
Old 02-13-2005, 05:29 AM   #4
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
fixing the quotes:

$ find -type f | sed -e "s/'/\\'/g" | xargs grep -e 'some regex...'

the sed call translates all "'" into "\'" (quote to backslash quote).
In case you have files containing other funny characters (# and " in particular), you may want to escape those as well.
have a look at either 'man sed' or 'info sed'.

Also, you might want to upgrade grep, find and xargs (I run 2.5.1 and 4.1.20 x 2, respectively).

hope this helps,

Jonas Kölker
 
Old 02-14-2005, 05:48 AM   #5
akudewan
Member
 
Registered: Apr 2004
Location: India
Distribution: Ubuntu
Posts: 364

Original Poster
Rep: Reputation: 31
Thanks for all the help jonaskoelker. I'll look into this more on google and on the man pages. I've got the overall gist.
 
Old 07-28-2014, 12:16 PM   #6
mltsy
LQ Newbie
 
Registered: Jul 2014
Posts: 1

Rep: Reputation: Disabled
Smile null delimiter!

In case anybody else is still finding this thread when searching for the same issue (like me):

find also has a -print0 option that separates output arguments with the null character, and xargs has a -0 flag to interpred arguments as delimited by the null character, which then also avoids interpreting backslashes and quotes as special. So:

find -type f -print0 | xargs -0 grep -e 'some regex...'
 
  


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
Double and single quote, Question in expect evilchild Programming 4 08-22-2004 05:34 PM
xargs question reitzell Linux - Newbie 4 07-04-2004 02:36 AM
LogWatch Cron :: Unmatched Entries elvisious Linux - Software 2 06-23-2004 07:10 AM
xargs: unmatched single quote fillatre Linux - Software 2 06-05-2004 10:04 PM
Strange problem (Unmatched Entries) 2HostMe Linux - Newbie 2 01-10-2004 08:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:44 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