csv file 1:
Scorecard_1,ZDTJ_PREV.EXT,12
Scorecard_2,ZACN_PREV.EXT,6
Scorecard_3,ABC.txt,8
Text File 2:
Acct_Bal_Non_Zero_Tgt.txt,7243
IDQ_HB1.txt,5380
IDQ_HB_LOGC.txt,5380
ZACN_PREV.EXT,4
ZDTJ_PREV.EXT,3
ABC.txt,10
Output:
Acct_Bal_Non_Zero_Tgt.txt,No_Match
IDQ_HB1.txt,No_Match
IDQ_HB_LOGC.txt,No_Match
ZACN_PREV.EXT,New_File
ZDTJ_PREV.EXT,New_File
ABC.txt,Old_File
Logic: If there is a matching file present in the second file the compare the last column of both the file. If last column in file one is greater than the last column of second file then the file is new else the file is old.
My task is to identify if the file is of current day or previous day based on the Interval ( which is last column of the first file. My approach is very trivial and I know there is a easier way through awk.
So far I have tried below:
File_in_CSV=$(cat file_1.csv | awk -F "," '{ print $3 }' | tail --lines=+1 | sort -u | uniq )
File_in_age_file=$(cat File_2.txt | awk -F "," '{ print $1 }' | tail --lines=+1 | sort -u | uniq )
Age=$(cat All_Files_Age.txt | awk -F "," '{ print $2 }' | tail --lines=+1 | sort -u | uniq )
Interval=$(cat scorecard_file_details.csv | awk -F "," '{ print $4 }' | tail --lines=+1 | sort -u | uniq )
for file in $File_in_CSV; do
if [[ "$file" = $File_in_age_file && $Age>$Interval ]]; then
printf "%s\n" "File is of Previous Day!"
else
printf "%s\n" "File is of Current Day!"
fi
done
I also want this flag of Previous day or current day to be appended as one column in any of the files. Thanks for your help on this!!
Example of expected Output is :
FileName, Flag
ABC.txt, New_File/Old_File