script help - pull date format out of file name and compare to today
I'm looking for some assistance in pulling a date format out of a file name and comparing it to the current date along with a retention value to determine whether or not to delete the file.
I'm reading 3 values from a .csv file
1. path to files
2. common naming convention of files
3. retention in days
.csv file would look like this:
filenames are in format logtype1_yymmdd.log
I want to pull out the yymmdd, compare it to todays date and the retention time and determine whether or not to delete it. I just need to strip off the common name which is defined and .log.
The values in the .csv file get read into following variables:
I can easily find the files by that name in the path using this cmd:
find $PTH -name $NAME*
I need help using probably awk or sed to strip the date out of the filename, compare it and remove the file if it's older than the retention period.
it would be ideal if I could do it on 1 line with a find -exec cmd.
I don't want to simply compare dates using a find function on create or modify date for a whole folder. I want to be specific about the files being removed.
If you post code back could you try to provide a bit of an explanation as to how the code works. Thanks.