I have several files named like this.
Now I want to retrieve the date from the file name and delete all files in this directory older than x days. I can retrieve date but it is not comparing.
Here is the code
#THRESHOLD=$(date -d "-1 day" +%d%m%Y)
THRESHOLD=$(date --date='-1 day' +%d%m%Y)
ls /var/logfiles//LogfileTest????????.txt |
sed 'h;s/[a-zA-Z.]/ /g;G;s/\n/ /' |
while read line1 line2 line3 a b DATE1 FILE e
d1=$(date -d "$D2" +%d%m%Y)
#echo "line2:" $line2
[[ $d1 -le $THRESHOLD ]] && ls $FILE
echo $(($THRESHOLD - $d1))
if expr "$d1" "<" "$THRESHOLD" ; then