LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 12-12-2009, 10:09 AM   #16
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,361

Rep: Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909

Quote:
Originally Posted by ghostdog74 View Post
don't need -iname
One of the requirements is "case insensitive" search, so yes... you need it. Anyway, at this point it is not clear what the OP requirement actually is. He posted just an example but he stated "I want to get all the files with b then c regardless of the number of spaces in between and regardless of case". Some of the suggested solutions match exactly this requirement.
 
Old 12-12-2009, 04:20 PM   #17
kj6loh
Member
 
Registered: Jun 2004
Posts: 43

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by colucix View Post
Why not simply a good-ol' pipe?
Code:
find . -type f | grep -E '.*[bB][ ]+[cC].*'
This is actually what I've been doing. I was just curious if there was a way to do this with just find. I'll take ghostdog's suggestion and play with it a bit more. Actually I used an i instead of [bB] and [cC] but that works too.

Last edited by kj6loh; 12-12-2009 at 04:35 PM.
 
Old 12-12-2009, 04:32 PM   #18
kj6loh
Member
 
Registered: Jun 2004
Posts: 43

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by catkin View Post
Sorry -- you are right; I misunderstood the requirement which is clearly expressed by example in this post
Yes thanks all, I'll play with it.

And yes I do have files like

ca ab
so there may be a letter between which I do not want to get.
So that would get filtered out. But thank you I have enough to play with.
 
Old 12-12-2009, 04:33 PM   #19
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,361

Rep: Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909
Quote:
Originally Posted by kj6loh View Post
This is actually what I've been doing. I was just curious if there was a way to do this with just find. I'll take ghostdog's suggestion and play with it a bit more.
Well, you will find a lot of suggestions in the posts above, using only the find command. The choice depends on your exact requirements. One of the downside of the grep solution is indeed the fact it matches the regexp through the full path of the file, even if the file name does not contain spaces (and a upper level directory does). The same if you use the -regex test of the find command, as clearly explained by Komakino in post #2, unless you use -regex, -iname and -type f together, as shown thereafter.
 
Old 12-12-2009, 05:14 PM   #20
kj6loh
Member
 
Registered: Jun 2004
Posts: 43

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by ghostdog74 View Post
because you are not going to call grep for every file it finds, even the ones that are not needed?? this produces overhead. Its better to let find do the walk and talk.

Code:
find . -type f <for OP to find out>  ".*b[ ]+c.*"
So if the above two are the same. I assume you left out -iregex from the bottom find. Why do they not produce the same results?
Code:
find . | grep -iE '.*b[ ]+c.*'
which I was doing anyway but as someone correctly pointed out this has lots of overhead. This does give the correct results. I test for the existence of directories elsewhere and am assured there are none. Thus no need for -type f.
Code:
find . -iregex '.*b[ ]+c.*'
This gives no results.
 
Old 12-12-2009, 05:38 PM   #21
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,361

Rep: Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909
Strange, it works for me:
Code:
$ ls -l
total 0
-rw-r--r-- 1 pippo users 0 2009-12-13 00:31 aaaaaaab               c
-rw-r--r-- 1 pippo users 0 2009-12-13 00:31 aaaaab  caaaa
-rw-r--r-- 1 pippo users 0 2009-12-13 00:31 aaaaC   B
-rw-r--r-- 1 pippo users 0 2009-12-13 00:31 aaaad daaaaaa
-rw-r--r-- 1 pippo users 0 2009-12-13 00:31 aaab   caaaa
-rw-r--r-- 1 pippo users 0 2009-12-13 00:31 aab       ccccaaa
-rw-r--r-- 1 pippo users 0 2009-12-13 00:31 aae   faa
-rw-r--r-- 1 pippo users 0 2009-12-13 00:31 baaac
-rw-r--r-- 1 pippo users 0 2009-12-13 00:31 b    c
-rw-r--r-- 1 pippo users 0 2009-12-13 00:31 B      Caaaa
-rw-r--r-- 1 pippo users 0 2009-12-13 00:31 ddddd
$
$ find . -iregex '.*b[ ]+c.*'
./aaab   caaaa
./aaaaaaab               c
./aab       ccccaaa
./B      Caaaa
./aaaaab  caaaa
./b    c
You can eventually try to change the regular expression syntax used by -iregex adding the -regextype option.
 
Old 12-12-2009, 05:42 PM   #22
kj6loh
Member
 
Registered: Jun 2004
Posts: 43

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by colucix View Post
Strange, it works for me:
Code:
$ ls -l
total 0
-rw-r--r-- 1 pippo users 0 2009-12-13 00:31 aaaaaaab               c
-rw-r--r-- 1 pippo users 0 2009-12-13 00:31 aaaaab  caaaa
-rw-r--r-- 1 pippo users 0 2009-12-13 00:31 aaaaC   B
-rw-r--r-- 1 pippo users 0 2009-12-13 00:31 aaaad daaaaaa
-rw-r--r-- 1 pippo users 0 2009-12-13 00:31 aaab   caaaa
-rw-r--r-- 1 pippo users 0 2009-12-13 00:31 aab       ccccaaa
-rw-r--r-- 1 pippo users 0 2009-12-13 00:31 aae   faa
-rw-r--r-- 1 pippo users 0 2009-12-13 00:31 baaac
-rw-r--r-- 1 pippo users 0 2009-12-13 00:31 b    c
-rw-r--r-- 1 pippo users 0 2009-12-13 00:31 B      Caaaa
-rw-r--r-- 1 pippo users 0 2009-12-13 00:31 ddddd
$
$ find . -iregex '.*b[ ]+c.*'
./aaab   caaaa
./aaaaaaab               c
./aab       ccccaaa
./B      Caaaa
./aaaaab  caaaa
./b    c
You can eventually try to change the regular expression syntax used by -iregex adding the -regextype option.
Hmmm just took it to my linux box and it works. But it doesn't work on my Mac.
 
Old 12-12-2009, 06:13 PM   #23
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,361

Rep: Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909
Quote:
Originally Posted by kj6loh View Post
Hmmm just took it to my linux box and it works. But it doesn't work on my Mac.
Sorry, I don't know much about Mac OS X. Which version of find does it use? What does the manual page of find report about the -regextype option?
 
  


Reply

Tags
find, whitespace


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 On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stripping lines versus stripping bytes in a bash subshell. poorman_installer Programming 9 10-21-2009 08:36 AM
Find/grep/wc command to find matching files, print filename and word count dbasch Linux - Newbie 10 09-14-2009 05:55 PM
[SOLVED] echoing whitespace from a command substitution GahseyFan Linux - General 2 05-16-2009 04:58 AM
find command and file names with whitespace sir_woland Linux - General 8 10-04-2007 07:10 PM
Making find do search in a directory that has whitespace in its pathname xode Linux - Software 2 04-18-2006 10:42 AM


All times are GMT -5. The time now is 08:06 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration