LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 08-10-2012, 03:57 AM   #1
rs232
Member
 
Registered: Oct 2005
Posts: 51

Rep: Reputation: 0
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!!!

Last edited by rs232; 08-10-2012 at 04:05 AM. Reason: improvement
 
Old 08-10-2012, 04:22 AM   #2
rs232
Member
 
Registered: Oct 2005
Posts: 51

Original Poster
Rep: Reputation: 0
I think I've found the solution, find really needs the parameter:
-regextype posix-extended

now it works :-)
 
Old 08-10-2012, 05:25 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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
 
Old 08-10-2012, 02:00 PM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,781

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by pixellany View Post
grep -E (or egrep)
sed -r
Fixed that for you.
 
Old 08-11-2012, 02:51 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by ntubski View Post
Fixed that for you.
Thank you!!!
 
  


Reply



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
Regular Expressions nova49 Linux - Newbie 4 07-13-2011 07:05 AM
[SOLVED] Using Regular Expressions With Find Crowey Programming 4 03-18-2010 01:33 AM
Regular Expressions ziggy25 Linux - Newbie 7 11-05-2007 06:57 AM
Regular Expressions markjuggles Programming 2 05-05-2005 11:39 AM
Using Regular Expressions to find unwanted characters professorfrink Programming 1 10-07-2003 01:34 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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