I have a configuration file that contains correct patterns and headers. I also have a folder with files such as:
ACCOUNT_20141125_17-13-12.csv
ACCOUNT_CLOSED_20141125_17-13-13.csv
CFT_IN_DETAILS_COPND_20141125_17-13-32.csv
CUSTOMER_20141125_17-13-18.csv
whose pattern I want to check. But I am having a problem with two files ACCOUNT_20141125_17-13-12.csv and ACCOUNT_CLOSED_20141125_17-13-13.csv because of the expression I am using. When I get the file name from Workflows.csv and try to find the oldest file with such name from another folder, for ACCOUNT_20141125_17-13-12.csv it always finds ACCOUNT_CLOSED_20141125_17-13-13.csv since both start with "ACCOUNT". How do I go about it? I have tried various ways which can be seen commented in my code below:
#!/bin/bash
CONF_FILE=/.../..../.../Script/conf
FOLDER=/.../../Script/files_to_check
DATE_LOG=`date "+%Y-%m-%d-%H.%M.%S"`
LOG_FILE=/../../Script/log_Script_$DATE_LOG.txt
cd "$CONF_FILE"
#loop through the configuration file
while read line
do
# collect the pattern and header of the csv files from conf
workflow_name=`echo $line | awk -F "|" '{print $1}'`
pattern=`echo $line | awk -F "|" '{print $2}'`
header=`echo $line | awk -F "|" '{print $3}'`
#str=`sed -e 's/\[0-9]{8}_[0-9][0-9]-[0-9][0-9].[0-9][0-9].csv'` #not working
#str=`find ./ -name "${pattern}*.csv" -type f -print | egrep "$pattern_[0-9]{8}_[0-9]{2}-[0-9]{2}-[0-9]{2}.csv"` #not working
str=`"${pattern}*.csv" -type f | egrep "$pattern_[0-9]{8}_[0-9]{2}-[0-9]{2}-[0-9]{2}.csv"` #not working
file="$FOLDER/${pattern}*.csv" #this causes problem with ACCOUNT AND ACCOUNT_CLOSED
#file="$FOLDER/${pattern}_$str" #not working
oldest_file=`ls -rt $file 2>/dev/null | head -1` # Get the names of the oldest file names
oldest_file_without_path=$(basename "$oldest_file") # Get the file name with it's path
echo "File: $file"
echo "Oldest file: $oldest_file"
#code continues here
done < $CONF_FILE/Conf.csv
Workflow.csv
WF_DWH_TPN_T24|ACCOUNT_CLOSED|ACCOUNT.NO;ACCT.CLOSE.DATE
WF_DWH_TPN_T24|ACCOUNT|ACCOUNT.NUMBER;CUSTOMER;CATEGORY;ACCOUNT.TITLE.1;ACCOUNT.TITLE.2;SHORT.TITLE;MNEMONIC;
Aucun commentaire:
Enregistrer un commentaire