Results 1 to 7 of 7
Noob alert...
I'm trying to filter out files that match certain criteria...
e.g. I want to list all files that contain the character sequences "pol" and "rim",
find . -type ...
- 12-12-2008 #1Just Joined!
- Join Date
- Dec 2008
- Posts
- 19
piping find to grep - syntax problem
Noob alert...
I'm trying to filter out files that match certain criteria...
e.g. I want to list all files that contain the character sequences "pol" and "rim",
find . -type file | grep "pol"
shows all files containing pol in their name...
find . -type file | grep "(pol|rim)"
shows nothing... how can I grep for various character sequences in this manner, or am I barking up the wrong tree?
Cheers
Steve
- 12-12-2008 #2
This will find any file on your root drive that has pol in the filename
# find / -name *pol* -print 2>/dev/null
- 12-12-2008 #3Just Joined!
- Join Date
- Dec 2008
- Posts
- 19
- 12-12-2008 #4Linux User
- Join Date
- Jun 2007
- Posts
- 318
Using just find
Using grep basic regular expresionsCode:find . -type f \( -name "*pol*" -o -name "*rim*" \)
Using grep extended regular expressionsCode:find . -type f | grep -e pol -e rim
Code:find . -type f | grep -E '(pol|rim)'
- 12-12-2008 #5Just Joined!
- Join Date
- Dec 2008
- Posts
- 19
That's great thanks!!!
Now I have had time to sit down and read the man page for find and grep, your replies are making more sense to me.
The -E option for grep... I can read this that is needed when extended regex evaluations are required... I'm just not sure what the diffeerence is between the abilities of basic and extended expressions. More reading required.
Anyway - your answer has also helped me to use grep to greater effect in general searching of my server logs now
Thanks!
- 12-13-2008 #6Linux User
- Join Date
- Aug 2006
- Posts
- 458
if you are not recursing directories, just use shell wild cards
Code:ls *rim* && ls *pol*
- 12-13-2008 #7Linux User
- Join Date
- Jun 2007
- Posts
- 318
ghostdog74,
Your example won't produce the desired results. He wants filenames with rim OR pol in them. Your command will execute 'ls *pol*' only if 'ls *rim*' is successful. If there are no files with rim in their names then the 'ls *pol*' won't execute.
If he wants find to stay within the current directory then he can use the '-maxdepth 1' option


Reply With Quote
