shellunixksh

Syntax to pull filename.ext*, but not filename.ext*.*


I mean I can't figure this one out so far.

file1.ext1
file7.ext2
fileQ.ext3
# should be accepted
file1.ext1.bak
# should not be accepted

@tim roberts - almost there, except file1.ext11 or file1.extAB won't work - but let me try a few things, t/u!


Solution

  • If you need to match both letters and numbers after .ext, you can try:

    ls -lh file*.ext+([0-9a-zA-Z])
    

    In the square brackets you can define which characters/ranges of characters should be accepted (or which explicitly shouldn't)

    If you want to accept everything but another dot(s), you can use @yvs2014's suggestion, where ^ is used for negation:

    ls -lh file*.ext+([^.])