to extract all the part of the filename before a particular word in the filename

Hi All,
Thanks in Advance

I am working on a shell script. I need some assistance.

My code:

if [ "$VERSION" = "1.1" ]
        then 
              set  "subscriber" "promplan" "mapping" "dedicatedaccount" "faflistSub" "faflistAcc" "accumulator"\
 "pam_account";
              for i in 1 2 3 4 5 6 7 8;
              do
              count=`ls /mnt/sf_MY_LAPTOP/SDPDUMP/*.csv|grep -i _\.csv$|wc -l`;
              if [ $count -eq 0 ]
              then
                                      touch <file_prefix>_$1.csv;
                    
              elif [ $count -gt 1 ]
              then
                    echo "Only one <file_prefix>_$1.csv file can be loaded at a time";
                   
              fi
              shift
              done
fi
done

1) There are some set of files in a directory like given below

OTP_UFSC_20120530000000_acc.csv
OTP_UFSC_20120530000000_faf.csv
OTP_UFSC_20120530000000_prom.csv
OTP_UFSC_20120530000000_subs.csv

I want to check if all thes files exists in the directory

the keywords are acc.csv, faf.csv, prom.csv, subs.csv
apart from this all the other things vary time to time (like the field seperator used in the file (can be.,-,_ etc) and the names OTP UFSC will vary.

2) if the file does not exist I have to touch (Create a empty file by that name)
Example : Imagine the file OTP_UFSC_20120530000000_acc.csv doesnot exist
in the directory
I have to search first if a file *acc.csv exist in the directory or not. If not i will extract the prefix (anything before acc.csv in this case OTP_UFSC_20120530000000_) from an existing file which is common to all the files in the directory
and create a file OTP_UFSC_20120530000000_acc.csv

:slight_smile:
Any suggestions and help

I am facing problems with my code

Please correct my code or suggest me with a better code