1828346 Members
3174 Online
109976 Solutions
New Discussion

linux wildcard

 
Duffs
Regular Advisor

linux wildcard

Hi,

I am attempting to write a script on Linux RH(9) Shrike that will fetch all files in the format `DEL<6_unique_digits>K` from a remote server.

My script works fine apart from fetching the actual filetypes that I need. For example I have tried all of the following combinations without any luck.....
FILESPEC=DEL*K
FILESPEC=^DEL\d\d\d\d\d\d\K
FILESPEC=`[^DEL]^[K]

........as you can I see I am running out of ideas for this, can anybody help?

Dermot
8 REPLIES 8
Stuart Browne
Honored Contributor

Re: linux wildcard

In terms of shell globbing, you've got a few choices:

DEL*K
DEL??????K
DEL[0-9][0-9][0-9][0-9][0-9][0-9]K

Obviously, the first will not restrict the interviening characters to 6.

The second will restrict it to 6 middle characters, but not what those characters are.

The third restricts the middle 6 characters to digits.

Now, you have to be careful where you use these however, as if you don't quote at the right time, they'll be expanded then, and not later when you want it to.
One long-haired git at your service...
Alexander Chuzhoy
Honored Contributor

Re: linux wildcard

This is how I'd do it with perl:
opendir DIR, "/root/perl";
for $_(readdir DIR)
{
print $_."\n" if /^DEL\d{6}K$/;
}
Hope it helps.
Alexander Chuzhoy
Honored Contributor

Re: linux wildcard

This is how I'd do it with perl:
opendir DIR, ".";
for $_(readdir DIR)
{
print $_."\n" if /^DEL\d{6}K$/;
}
Hope it helps.
Duffs
Regular Advisor

Re: linux wildcard

Unfortunately this Perl solution does not work with Linux shell scripting.
D.
Gopi Sekar
Honored Contributor

Re: linux wildcard


you can try this

FILESPEC=DEL[0,9]{1,6}K

which will match the files containing the string "DEL<1 to 6 digits>K" anywhere in the file.

As you can see it with match both DEL1K and DEL123456K. so if you want it to be specific about the number of digits, use this:

FILESPEC=DEL[0-9]{6,6}K

Hope this helps,
Gopi
Never Never Never Giveup
Duffs
Regular Advisor

Re: linux wildcard

It is actually coming back with the following error message:

ncftpget: server said: Specified object name too long, limit is 10 characters: DEL[0-9]{6,6.
+ ERRCODE=3

Apologies about this but I have just discovered that the remote server I am trying to grab these files from is a OS/400. Does this help?

D.
Gopi Sekar
Honored Contributor

Re: linux wildcard


oops, are you using this on OS 400? I am sorry, this pattern matching will work on newer versio n of bash shell in linux and I really doubt whether the shell available in OS 400 does really support pattern matching at all.

Never Never Never Giveup
Stuart Browne
Honored Contributor

Re: linux wildcard

Umm, atom repitition like that ([0-9]{1,6}) is a RegularExpression, not a path-globbing format.

{} braces in most bourne-based shells (including ksh & bash) is treated as multiple-parts, i.e. file{1,2} = file1 file1.

Not even bash 3.00.16 (part of FC4) has reguler-expression globbing.
One long-haired git at your service...