I'm trying to swap the date in a log file's name using a bash script. I cannot seem to get the date's to play nice however.
When I try to swap the dates using sed
, the original date is still in the filename (I'm echoing instead of using mv
for now):
#!/bin/bash
DATE=`date +%Y-%m-%d`
YESTERDATE= date -d 'yesterday 13:00' '+%Y-%m-%d'
echo "$DATE"
echo "$YESTERDATE"
for LOGFILE in *.$DATE;
do
newfile="$(echo ${LOGFILE} |sed -e 's/$DATE/$YESTERDATE/')" ;
echo "$newfile"
#mv -- "$LOGFILE" "$newfile";
done
The log files I want changed are only the ones with todays date in them. The format is log_file.log.2018-07-17
. I want it to be changed to log_file.log.2018-07-16
.
Is the issue with how I am using variable names in the sed
command?