How to match?

Hi,

I have to find certain directory patterns.
All my patterns are in a property file.
One of directory patterns is :ABCmmddyyyy. (i.e ABC followed by 8 digits")

How can i find all the directories of this pattern by specifying a pattern in the property file

mypattern.properties

pattern1= ABC????????

Thanks!

are you asking for a regular expression to match ABC12345678? if so

^ABC\d{8,8}$

might do, if the engine using the pattern utilises PCRE.

find /PATH -type d -name "*ABC[01][0-9][1-3][0-9]200[0-9]*" 

Thanks guyzz.

Since i have ABCmmddyyyy. (i.e ABC followed by 8 digits") as one of the directory patterns.
Can i have the place the pattern mentioned by "rdcwayx" in the property file and read it in the "find" command.

Wempy can u please elaborate a bit.. i didn't exactly get

^ABC\d{8,8}$

That regular expression matches a string that:
(a) begins with the characters A, B and C, and
(b) is then followed by exactly 8 digits (0-9)

An equivalent regex is:

^ABC\d{8}$

Note that these regexes simply check for "8 digits after ABC" and not "8 digits after ABC that constitute a valid date of form MMDDYYYY".
If you want to do that, then that's a different problem altogether.
Otherwise, if those 8 digit numbers need not be validated, then these regexes can work.

tyler_durden

some updates, help to find out the folder name follow the date format.

find /PATH -type d |grep "ABC[01][0-9][1-3][0-9]200[0-9]"

I think it should be:

"ABC[01][0-9][0-3][0-9]20[0-9][0-9]"

You can use grep -f to use a pattern stored in a file

$> cat pattern
ABC[01][0-9][0-3][0-9]20[0-9][0-9]
find /PATH -type d|grep -f pattern

You can use extended regular expressions to be more precise, e.g.:

find /PATH -type d|egrep "ABC(0[1-9]|1[0-2])([0-2][0-9]|3[01])(19|20)[0-9][0-9]"

And you can combine that with a pattern file

find /PATH -type d|egrep -f pattern

I have many other patterns which i need to read from property file.
I can't harden my logic around a particular pattern.

so i think specifying this code below in the property file and read the pattern in the "find" command should work.. lemme give it a try.

^ABC\d{8}$

By the way what does "$" signify in

^ABC\d{8}$

Cheers!

$ means end of line