tclglobnegation

TCL glob negative match when listing files


I have a directory containing some files (e.g.):

SASA_AMK12.txt
SASA_AMK13.txt
SASA_AMK5.txt
SASA_AMK9.txt
SASA_ATH10.txt
SASA_PSK.txt
SASA_ProtAMK12.txt
SASA_ProtAMK13.txt
SASA_ProtAMK5.txt
SASA_ProtAMK9.txt
SASA_ProtATH10.txt
SASA_ProtGSK.txt

For listing these files I'm using this glob:

set SASA_LIG_PROCESSED [lsort [glob -directory "${WORKDIR}/" -type f -tails *{SASA}*]]

However, what I want is to negate the match in the glob by excluding from listing all the filenames that contain "Prot" pattern. So, the desired output should be:

SASA_AMK12.txt
SASA_AMK13.txt
SASA_AMK5.txt
SASA_AMK9.txt
SASA_ATH10.txt
SASA_PSK.txt

I tried already with something like SASA*?!Prot* but it is not working. How to solve this?


Solution

  • Do it two steps. First use glob to get a list of files like you're doing now, and then lsearch with the -not and -all options to filter out the ones you don't want.

    # set SASA_LIG_PROCESSED [glob -directory "${WORKDIR}/" -type f -tails {*SASA*}]
    set files {
        SASA_AMK12.txt
        SASA_AMK13.txt
        SASA_AMK5.txt
        SASA_AMK9.txt
        SASA_ATH10.txt
        SASA_PSK.txt
        SASA_ProtAMK12.txt
        SASA_ProtAMK13.txt
        SASA_ProtAMK5.txt
        SASA_ProtAMK9.txt
        SASA_ProtATH10.txt
        SASA_ProtGSK.txt
        }
    
    set SASA_LIG_PROCESSED [lsort -dictionary [lsearch -all -inline -not $files {*Prot*}]]
    puts $SASA_LIG_PROCESSED
    # SASA_AMK5.txt SASA_AMK9.txt SASA_AMK12.txt SASA_AMK13.txt SASA_ATH10.txt SASA_PSK.txt