I'm trying to rename files using tr
. The following command nearly works:
for file in ./*; do mv -v "$file" $(echo "$file" | tr ' []' '-' | tr -dc 'A-Za-z0-9_-' | tr '[:upper:]' '[:lower:]'); done
However, the command also strips dot characters. So, this file:
St Nicholas' church from NE [1235] 1936-08-01.jpg
becomes
st-nicholas-church-from-ne--1235--1936-08-01jpg
I've tried various ways to escape the dot, for instance using tr -dc 'A-Za-z0-9\._-'
and tr -dc "A-Za-z0-9\._-"
The result invariably is that every character gets deleted. So my question, how to properly escape dot character in tr -dc
?
tr
doesn't use regular expressions. – Kusalananda Dec 30 '16 at 15:55