> == kevin lyda
>> == Jerry Walsh
>> You could also just do:
>> ls foo*[^re]c
> no. unless tcsh implements regexp's *really* weird, that means a
> string beginning with foo, contains any number of chars for a while,
> and then has a char that is neither r or e, and then the last char
> is c. so the following starred files would be listed in your
> example:
No, no.
Two misconceptions here.
First of all, '*' in a regular expression doesn't mean "any sequence
of characters", it means "zero or more instances of the previous
item", so in a *regular expression* context, "foo*[^re]c" would match
a (sub)string starting with "fo", then any number of "o"s, then any
character except "r" and "e", and finally a "c".
However, shell globbing does *not* use regular expressions; it uses
"glob patterns", which are different (and simpler and less powerful).
It may be possible to use "just" shell globbing to get a list of files
which match "*c" but not "*rec", but it really is easier to use
something like grep here.
*If* it's only files ending in "ec" which you want to exclude, you
could do "*[^e]c", which would give you all files ending in "c" except
those where the second last letter is "e"; this is a bit flaky,
though, as it relies on previous knowledge of the space of filenames.
files=$(ls -1 *c | grep -v 'rec$')
is better.
Colm
--
Colm Buckley @ NewWorld Commerce
Business: +353 1 4334334 / colm at nwcgroup.com / http://www.nwcgroup.com/
Personal: +353 87 2469146 / colm at tuatha.org / http://www.tuatha.org/~colm/
Hard work pays off in the future. Laziness pays off now.
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!