Pattern matching problem

if i have to do pattern match for file name with digit alphanumeric value like this

File_1234.csv
File_12sd45rg.csv

i am using this File_[0-9a-zA-Z]*.csv
and File_[0-9]*.csv for digit pattern match.

when i am doing pattern match for the digit then both alphanumeric match
and digit match is coming.
where only digit match should should come.
If usinng [:digit:] then it is not working.

the part of code which i am using is like this

i=0
len=${#arr[@]}
echo $len

shopt -s extglob

pattern=*[0-9]*.*
pattern1=*[0-9]*_[0-9]*.*
pattern2=*[a-zA-z0-9]*.*
pattern3=File_[0-9]*_[0-9]*.csv
pattern4=File_[a-zA-Z]*_[a-zA-Z]*.csv
pattern5=File_[a-zA-Z0-9]*_[a-zA-Z0-9]*.csv
pattern6=File_[0-9]*[a-zA-Z]*.csv

while [ $len -gt $i ]
do
  case ${arr[$i]} in
  $pattern) echo "pattern %N% match" ;;
  esac
  case ${arr[$i]} in
  $pattern1) echo "pattern %N%_%N% match" ;;
  esac
  case ${arr[$i]} in
  $pattern2) echo "pattern %x% match" ;;
  esac
  

This seems to be a slight expansion of this thread that you started a couple of days ago discussing the same topic.

In the last two days the way case statements evaluate expressions has not changed. Case statements still perform filename pattern matches; not regular expression pattern matches.

i am using it as you said but when and operator is used then it is not working

Input=($( sqlplus -s rte/rtet1@him60t1 << EOF
set heading off
select FILE_NAME_DTTM FROM prd_frg_file_jrnl where FILE_KEY > $val;
EOF
))
echo $Input


i=0
len=${#arr[@]}
echo $len

for i in "${arr[@]}"
do      printf "Processing %s:\n" "$i"
        if [[ "$i" =~ [a-bA-Z0-9][0-9]+.[a-z] ]]
        then    echo '%N% FILE MASK PASS'
        elif [[ "$i" =~ [a-zA-Z0-9][0-9]+_[0-9]+.[a-z] ]]
        then    echo '%N%_%N% FILE MASK PASS'
        elif [[ "$i" =~ [a-bA-Z0-9][0-9]+.[a-z] ]] && [[ "$Input" != "no row selected" ]]
        then    echo '%SE% FILE MASK PASS'
        elif [[ "$i" =~ [a-bA-Z0-9][a-zA-Z]+.[a-z] ]]
        then    echo '%C% FILE MASK PASS'

        else    echo 'No match'
        fi

done

can you please check where i am going wrong

The regular expressions you're using in this message do not even come close to matching the patterns you had in the 1st message in this thread. Without knowing what the formats are for the filenames you're trying to match, it is impossible to guess at why you're not matching the filenames you want to match. But there are three obvious problems.

  1. What output are you seeing from the command:
    text echo $Input
    in your script.
    The way you set the array variable Input (as marked in red in your code above) will produce an array containing three elements "no", "row", and "selected" rather than a single element "no row selected" unless the sqlplus command returns a quoted string. If it is three elements instead of one, you would need to change:
    text [[ "$Input" != "no row selected" ]]
    to:
    text [[ "${Input[@]}" != "no row selected" ]]
    to get the desired result.
  2. If you have an if statement that starts with if a and a later clause in that same statement of the form elif a && b , then the then clause of the elif clause can NEVER be executed. The code I marked in Dark Orange in your code above corresponds to a . Therefore, the
    text && [[ "$Input" != "no row selected" ]]
    in your code above will never be executed.
  3. I was careless in the other thread on this topic when I suggested using ".csv" as a regular expression to match the string ".csv". The period in this regular expression will match any character (not just a period). When you know that all of your input files have a period followed by a filename extension and you want to verify that the filename you're processing has the extension .csv, it doesn't make much difference. You now seem to be looking for a single lowercase letter following a period following a bunch of other characters. The expressions you're using will match any filename that ends with three characters where the first is alphanumeric, the second is any character, and the 3rd is a lowercase alphabetic character. Since I don't know what filenames you're trying to match, I strongly suggest that you use a bracket expression [.] or a collating element expression [...] to match the period. (You could also just escape it with a backslash, but if you want to use a variable containing a string as a way to save the expressions you want to use, you have to worry about how many backslashes you need to be sure that you actually end up with exactly one backslash in the RE in [[ string =~ RE ]] after string processing and quote removal occurs.)