How to find regular expression for two files?

I have files:

 
 sum_<INPUT FILENAME>.YYYYMMDDhhmmss.csv
 

and

 
 sum_details_<INPUT FILENAME>.YYYYMMDDhhmmss.csv
 

I have no idea, what is input filename, but in the code I would like to catch them in case

 
 I process them in the loop above case statement
 for *.${Today}.*.txt *.${TODAY}*.csv
 do
 firstpreffix=`echo ${file} | cut -d'_' -f 1`
 case ${firstpreffix} in
      sum)
            if [ $file = "sum_INPUT FILE" ];then
                  do something
            else
                  do something
           fi
 esac
 done
 

The problem for me is if I make

 
 if [ $file = sum_*.*.csv ];then
 

Statement can catch both files. I need to process them separate

Thanks for contribution
My system is AIX and borne shell

Try something like:

case $file in 
  sum_details_*.*.csv)
    do something ;;
  sum_*.*.csv)
    do something else ;;
sac

Don't you think, that

 file sum_*.*.csv will get sum_details_*.*.csv. sum_* and sum_detail*...
 

No, because sum_*.*.csv is below sum_details_*.*.csv in the case statement. The order is essential, because the matches are top to bottom. Once a match is found, other patterns will not be tried.

So if the filename is sum_details_<INPUT FILENAME>.YYYYMMDDhhmmss.csv , then the first pattern will match sum_details_*.*.csv and therefore it will not be matched by sum_*.*.csv

1 Like