Results 1 to 10 of 12
I hope you can put me in the correct path as I am having a bit of
difficulty writing a script to search for directories that begin with
2 characters ...
- 06-15-2009 #1Just Joined!
- Join Date
- Jun 2009
- Posts
- 3
Script Problem
I hope you can put me in the correct path as I am having a bit of
difficulty writing a script to search for directories that begin with
2 characters and 3 numbers and does not mater about the rest of the
name of the directory for example:
GS001_Anything_test
TS636_Test
Ideally I would like to pattern match [any 2 characters] and
[3 numbers]and the rest as a *
I hope my problem that makes sense
Please Help
- 06-15-2009 #2
Hi,
you will have to learn regular expressions for this.
With these, you can write critera like
[:alpha:] for characters, [:digit:] for numbers.
Regular expression - Wikipedia, the free encyclopediaDebian GNU/Linux -- You know you want it.
- 06-15-2009 #3Just Joined!
- Join Date
- Jun 2009
- Posts
- 3
Scripts problem
do you mean like the following
find /usr -name [abcdefghijklmnopqrstuvwxyz]+[1234567890]+*
how do you fix the find and make it search from the left and only upto 6 characters and numbers until it reaches _*
then display results
- 06-15-2009 #4Debian GNU/Linux -- You know you want it.
- 06-23-2009 #5Banned
- Join Date
- Jun 2009
- Posts
- 68
The regular expression I believe you're talking about would be:
to match. Printing it's dependent on what you use to match and print. I'm not so sure.Code:/([A-Z]|[a-z]){2}\d{3}.*/
- 06-23-2009 #6Banned
- Join Date
- Jun 2009
- Posts
- 68
[abcdefghijklmnopqrstuvwxyz]+[1234567890]+*
is a regular expression matching:
at least one lowercase character followed by at least one digit (an asterisk would mean any number of times, but I believe the syntax to be wrong (just [0-9]+* alone is like saying at least one digit any number of times). It will complain and not work correctly using PERL, written this way - with a message of nested quantifiers in regex.)
It can be written simply as /[a-z]+\d+/, without the asterisk, but it's not the right regular expression for the job.
- 06-27-2009 #7Linux User
- Join Date
- Aug 2006
- Posts
- 458
- 06-28-2009 #8Banned
- Join Date
- Jun 2009
- Posts
- 68
I used a regular expression like you would use in PERL, but I know there are variations with find, sed, etc. Not trying to sound like an expert, but I didn't realize that there was quite so much difference between PERL regular expressions and these, also ... I thought the {2} {3} would be pretty much universal. I kind of rushed into it, I took for granted there were even more similarities. Apologies, won't happen again.
- 07-01-2009 #9Just Joined!
- Join Date
- Jun 2009
- Posts
- 3
thank you all and to "ghostdog74" much appreciated.
find /path -type d -name "[a-zA-Z][a-zA-Z][0-9][0-9][0-9]*"
What do I need to do to display any directory found inside a parent directory based on find patern matching.
For example
[parent Directory1]
GS001_Anything_test
TS636_Test
[parent Directory2]
GS001_Anything_test
TS637_Test
[parent Directory3]
TT001_Anything_test
TB636_Test
Thanks for all your advice and help.
- 07-02-2009 #10Banned
- Join Date
- Jun 2009
- Posts
- 68
I am very sure that the last asterisk is only applying to the last [0-9]. It's saying any amount (even 0) of [0-9]. To say anything after the last [0-9] would be .*


Reply With Quote

