0
master_sheet_2022_03_25_1141.csv
master_sheet_2021_03_30_1034.csv
master_sheet_2021_03_31_1857.csv 
master_sheet_2021_03_31_1930.csv 
master_sheet_2021_03_31_2037.csv 
master_sheet_2021_03_31_2109.csv 

For each file in above directory, rename the file but append master_sheet

master_sheet__$(date "+%Y.%m.%d-%H.%M.%S").csv"

eg: master_sheet__2022_04_06_09:30

Here is my current script

#!/bin/bash

find . -type f -name "*.csv" | \
while read -r files; do 
    mv "$files" "${files%.*}_$(date "+%Y.%m.%d-%H.%M.%S").csv"
# for files in *; do echo "${files%.*}"; done
done

Current output

master_sheet_2022_03_22_1351_2022.04.06-09.14.00_2022.04.06-09.19.27_2022.04.06-09.20.12
master_sheet_2022_03_29_1043_2022.04.06-09.14.00_2022.04.06-09.19.27_2022.04.06-09.20.12
  • try with a simpler loop, `for file in *.csv; do ...; done` should work just fine – Aaron Apr 06 '22 at 07:36
  • Your question is hard to understand. Please show names of files *before* and expected names *after* running your script. What if you have 10 files called `1.csv` through `10.csv` and you rename them all with the current time and your script can process 100 files per second? You will lose 9 of your files and end up with 1 file with current time, won't you? – Mark Setchell Apr 06 '22 at 08:39
  • @MarkSetchell Thats exactly what i want to avoid, before **master_sheet_2022_03_25_1141.csv** after **master_sheet_2022_04_06_1053.csv** next file incriment by 1 second **master_sheet_2022_04_26_1054**.csv and so on... – kebogile Porogo Apr 06 '22 at 08:53
  • Please use [edit] to put the critical information above in your question rather than forcing users to scrabble around in the comments. Thank you. Neither your question nor your code seem to mention incrementing anything AFAIK. – Mark Setchell Apr 06 '22 at 10:18

0 Answers0