Remove timestamp from file name

This script took a bit of work…

I receive files that are in the format of:
file_MMDDYYYYHHMIS.csv

Example: file_09022022102012345.csv

OK, so I’m not quite sure what the last digits are…all I knew is that I had to strip 9 digits out of the filename in order to just get file_date.csv

Here’s the code I used:

for file in *.csv
do
# For future reference, look for 9 numbers followed by a
# .csv and then replace that with .csv
# sed requires the {}s to be escaped, along with the .
new=$(echo $file | sed -e ‘s/[0-9]{9}.csv$/.csv/’)
# echo OLD$file
# echo NEW$new
mv $file $new
done