I have a file with the name data_extraction_check_03_02_2021.txt. I am trying to get the last three values from the filename which is in the order of date, month and year. After that, I need to concatenate three variables and convert it to a date format so that I can find out how many days are in between that date and current date.
Using the below command, I get the last filename which is the "data_extraction_check_03_02_2021.txt".
latest_file=$(ls -t | head -n 1)
echo $latest_file
I am trying to get the date_last, month_last & year_last using the below commands but I get the error "date_last:command not found"
date_last = echo "${latest_file}" | awk -F'[_.]' '{print $4}'
month_last = echo "${latest_file}" | awk -F'[_.]' '{print $5}'
year_last = echo "${latest_file}" | awk -F'[_.]' '{print $6}'
After that, I concatenate the date_last, month_last & year_last using the below command. Not sure how to convert this to a date format.
last_extracted_date=$(echo ${date_last}-${month_last}-${year_last})