Running this script in the same directory containing folders with names having the pattern DD.MM.YYYY-X
will copy those folders in the same directory with naming syntax you requested.
script2.sh
file containing the following
#!/bin/bash
for dir in $(find . -maxdepth 1 -name "*-*" -type d -exec basename {} \;) ;do
dd=$(cut -d'.' -f1 <<< "${dir}")
mm=$(cut -d'.' -f2 <<< "${dir}")
yyyy=$(cut -d'.' -f3 <<< "${dir}" | cut -d'-' -f1)
yy="${yyyy: -2}"
x="${dir: -1}"
cp -rvi "${dir}" "${yy}${mm}${dd}I${x}"
done
exit 0
Script Output
'22.12.1983-1' -> '831222I1'
'22.12.1982-1' -> '821222I1'
'22.12.1983-0' -> '831222I0'
'22.12.1982-2' -> '821222I2'
ls
output after running script
22.12.1982-1 22.12.1982-2 22.12.1983-0 22.12.1983-1 821222I1 821222I2 831222I0 831222I1 script2.sh
Recommendation (Update #1)
It is recommended to update and use unique variable names. Like with a _
prefix.
Here dd=
variable can be changed to _dd=...
to avoid conflicting/confusing with the dd
command.