Tuxedo <
tux...@mailinator.net>:
… and if by mistake, the script is run once more, there will be file
names containing a triple of identical date info…
>How can I remove the 16 characters in each filename, by renaming all files
>in the current working directory to retain only the last 28 last characters?
>
>But so I don't rename filenames that may still exist in the same directory
>which are still correctly named, the procedure should apply only on files
>which are exactly 44 characters long as the wrongly named files in this
>example are.
>
I suggest a slightly different solution:
For each filename, check, whether it starts with a sequence of at
least two identical patterns each consisting of 8 digits, one
underscore, 6 digits and one underscore. If that's the case,
strip all but one of these patterns from the start of the
filename.
(
for f in *.jpg
do
if sequence="$(
expr ' '"$f" : \
' \(\([[:digit:]]\{8,\}_[[:digit:]]\{6,\}_\)\2\{1,\}\)'
)"
then
date_info="${sequence%${sequence#????????_??????_}}" &&
renamed_f="${date_info}${f#${sequence}}" &&
mv -i -- "$f" "$renamed_f"
fi
done
)