Code:
$ cat timestamp_format.csv | awk -F"," -v OFS="," '{print $1,$2,$3,$4}' | while IFS="," read FILE_TIMESTAMP FILE_TIMESTAMP_PARAM FILE_TIMESTAMP_REGEX EXP_FILE_TIMESTAMP_FORMAT
do
awk -v OFS="|" -v FILE_TIMESTAMP="${FILE_TIMESTAMP}" -v FILE_TIMESTAMP_REGEX="${FILE_TIMESTAMP_REGEX}" -v EXP_FILE_TIMESTAMP_FORMAT="${EXP_FILE_TIMESTAMP_FORMAT}" 'FNR==NR{a[NR]=$1;b[NR]=$3;c[NR]=$4;CNT=NR;next}
{
SOURCE_FILENAME=$4
TARGET_FILENAME=$5
for (i=1;i<=CNT;i++)
{
VAR=a[i];
DATE_FORMAT_REGEX=b[i];
S1=index($4,VAR);
L1=length(VAR);
S_FTP_FILE_TIMESTAMP1=index(SOURCE_FILENAME,FILE_TIMESTAMP);
L_FTP_FILE_TIMESTAMP1=length(FILE_TIMESTAMP);
TEMP_SOURCE_FILENAME=sub(VAR,DATE_FORMAT_REGEX,SOURCE_FILENAME);
S2=index(SOURCE_FILENAME,VAR);
L2=length(VAR);
S_FTP_FILE_TIMESTAMP2=index(SOURCE_FILENAME,FILE_TIMESTAMP);
L_FTP_FILE_TIMESTAMP2=length(FILE_TIMESTAMP);
for (j=1;j<=CNT;j++)
{
DVAR=a[j];
EXP_DATE_FORMAT=c[j];
DS1=index($5,DVAR);
DL1=length(DVAR);
DS_FILE_TIMESTAMP1=index(TARGET_FILENAME,FILE_TIMESTAMP);
DL_FILE_TIMESTAMP1=length(FILE_TIMESTAMP);
TEMP_TARGET_FILENAME=sub(VAR,DATE_FORMAT_REGEX,TARGET_FILENAME);
DS2=index(TARGET_FILENAME,DVAR);
DL2=length(DVAR);
DS_FILE_TIMESTAMP2=index(TARGET_FILENAME,FILE_TIMESTAMP);
DL_FILE_TIMESTAMP2=length(FILE_TIMESTAMP);
if ( S1 > 0 && DS1 > 0 && S_FTP_FILE_TIMESTAMP1 > 0 && DS_FILE_TIMESTAMP1 > 0 )
{
print $0,S1,L1,substr($4,S1,L1),DATE_FORMAT_REGEX,S_FTP_FILE_TIMESTAMP1,L_FTP_FILE_TIMESTAMP1,FILE_TIMESTAMP,FILE_TIMESTAMP_REGEX,S2,L2,substr($4,S2,L2),DATE_FORMAT_REGEX,S_FTP_FILE_TIMESTAMP2,L_FTP_FILE_TIMESTAMP2,FILE_TIMESTAMP,FILE_TIMESTAMP_REGEX,DS1,DL1,substr($5,DS1,DL1),EXP_DATE_FORMAT,DS_FILE_TIMESTAMP1,DL_FILE_TIMESTAMP1,FILE_TIMESTAMP,FILE_TIMESTAMP_REGEX,EXP_FILE_TIMESTAMP_FORMAT,DS2,DL2,substr($5,DS2,DL2),EXP_DATE_FORMAT,DS_FILE_TIMESTAMP2,DL_FILE_TIMESTAMP2,FILE_TIMESTAMP,FILE_TIMESTAMP_REGEX,EXP_FILE_TIMESTAMP_FORMAT
}
}
}
}' FS="," date_format.csv FS="|" RECORD
done
$