Home > Archive > AWK > May 2006 > matching glob patterns?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
matching glob patterns?
|
|
| danmc91 2006-04-17, 6:56 pm |
| Anyone have some awk code for matching glob style patterns? I want to
be able to match things like:
foo+-{,-bin,-gtk{1,2}}-2.3{,p[0-9]}
probably by converting it to
foo\+-(()|(-bin)|(-gtk((1)|(2)))-2\.3(()|(p[0-9]))
and then just matching with the normal awk regexp matching.
The context for this is I have two lists that I've read from somewhere,
a and b. I want to do something like:
for( i in a) {
name = a[i];
for(j in b) {
pat = b[j];
reg = glob2regexp(pat);
if( name ~ reg) {
print "we have a match";
}
}
Thanks
-Dan
| |
| John DuBois 2006-04-17, 6:56 pm |
| In article <1145303892.749613.234890@v46g2000cwv.googlegroups.com>,
danmc91 <spam@mcmahill.net> wrote:
>Anyone have some awk code for matching glob style patterns? I want to
>be able to match things like:
>
>
>foo+-{,-bin,-gtk{1,2}}-2.3{,p[0-9]}
>
>probably by converting it to
>
>foo\+-(()|(-bin)|(-gtk((1)|(2)))-2\.3(()|(p[0-9]))
>
>and then just matching with the normal awk regexp matching.
ftp://ftp.armory.com/pub/lib/awk/glob2ere
It does sh-style globbing, but not brace expansion (which isn't part of
globbing). If it were to be expanded, the right way of handing more complex
requirements would be to do ksh(etc.)-style extended globbing.
John
--
John DuBois spcecdt@armory.com KC6QKZ/AE http://www.armory.com/~spcecdt/
| |
| subPlanck@excite.com 2006-05-07, 6:59 pm |
| John,
I may have stumbled on a related problem underr a different OS: I use
MKS Toolkit's awk in a DOS box under Win XT, and noticed that my batch
files calling awk scripts won't run if the filenames are expanded with
square bracket expressions. For example,
$ dcap KWM*123*
will run just fine, but
$ dcap KWM*[1,3]*
won't, where dcap.bat is a batch file like
@awk -f awkscript.awk %1
where %1 would be substituted by the offending
square-bracker-containing filename.
I've tried escaping the brackets with \, ', " etc., but to no avail...
--z.entropic
|
|
|
|
|