Help with renaming file using sed

Hi,

I am currently updating a script, It should do the ff:

rename the YYYYMMDD in mainlog.YYYYMMDD to $NEW_DATE

I was ask to use sed but I am not that familiar with it.

I should update the touch part with the sed. Please kindly help me with this. Thanks a lot.

#----------------------------------------------------------------
# loop to touch the mainlog and archive_list files
#----------------------------------------------------------------
integer INDEX=1
OUT_DD="00"
while [ $INDEX -le $UPPER_LIMIT ]
do
OUT_DD=$INDEX
if [ $INDEX -lt 10 ] 
then
NEW_DATE="$OUT_YYYY""$OUT_MM"0"$OUT_DD" # insert day with leading zero 
else
NEW_DATE="$OUT_YYYY""$OUT_MM""$OUT_DD"
fi
 
touch -t ${NEW_DATE}"0000.01" ./logs/ctlm/mainlog.${NEW_DATE}.log

Hi,

in a shell environment what you may do is using sed to generate the new file name you want to rename the original file to, i.e.

[...]
currentname=mainlog.YYYYMMDD.log
newname=`echo ${currentname} | sed -e "s/\.[0-9]\{8\}\./\.${NEWDATE}\./" 
mv ${currentname} ${newname}
[...]

see ya
fra

Hi Fra..

I tried using the code but i was getting a not found error.

currentname: not found

would you know why?

thanks for the help..

Hi,
check your definition of currentname variable, and if there actually is a file named like the value set in currentvalue variable.

see ya
fra