[ILUG] listing files
colm at tuatha.org
Mon Jul 16 12:28:41 IST 2001
> == 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
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$')
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.
More information about the ILUG