LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   find and regular expressions (https://www.linuxquestions.org/questions/programming-9/find-and-regular-expressions-4175421358/)

rs232 08-10-2012 03:57 AM

find and regular expressions
 
Hi all,

I could be me, but i don't seem to be able to make find working with regular expressions :-(

I've tried the parameter -regex followed by a countless number of attempts to get something out of it with no luck.

What I'm trying to find is:

1) directory names that have no space or multiple spaces before the character "["

2) directory names where tha value between square brackets is higher than 2012 e.g. "[2200]"

When I test my regular expressions against a regular-expression verification software it does the job, but when i use the very same strings with find... no luck!

e.g.

mywonderfuldirectory [2459]

find . -type d -regex ".*\[[0-9]{4}\]"

nothing is found

Can anybody please provide a working example?


Many thanks!!!

rs232 08-10-2012 04:22 AM

I think I've found the solution, find really needs the parameter:
-regextype posix-extended

now it works :-)

pixellany 08-10-2012 05:25 AM

You may already know this, but many utilities require some kind of option setting when using extended regexes---eg
grep -e (or egrep)
sed -r

ntubski 08-10-2012 02:00 PM

Quote:

Originally Posted by pixellany (Post 4750764)
grep -E (or egrep)
sed -r

Fixed that for you.

pixellany 08-11-2012 02:51 AM

Quote:

Originally Posted by ntubski (Post 4751108)
Fixed that for you.

Thank you!!!


All times are GMT -5. The time now is 09:58 AM.