Reputation: 71
I am curious if I could negate POSIX class while performing pattern matching. I have following:
file file1 file10 file2 file3 file4 file5 file6 file7 file8 file9
Say, I want to ls -l only file : all the files with no digit in the end. I tried following :
ls -l *[^[[:digit:]]]
ls -l *[!digits]
ls -l *[[!:digit:]]
None of above works. That actually work, to some extend (I get file10):
ls *[^1-9]
But that's not a point. And for the record I know that the easiest would be:
ls -l | egrep -v ".*[[:digit:]]$"
Is there any way to negate POSIX class?
Upvotes: 1
Views: 138
Reputation: 785266
You can use *[![:digit:]]
to match files not ending with digits:
printf "%s\n" *[![:digit:]]
file
Upvotes: 4
Reputation: 241918
The outer square brackets denote the character class. The inner ones denote the POSIX class. Negate the character class:
ls -l *[![:digit:]]
Upvotes: 4