I would like to sync several folders on my local Mac with a remote server via SFTP. As the existing umlauts appear to be problematic for my syncing software (Deltawalker), I am looking for a way ro rid the filenames of any problematic characters.

There are several programmes (I am currently trying PowerRenamer, but there are several to replace characters based on regular expressions but I can't seem to figure out what kind of RegExp I need to use. Replacing single occurrences are easy but having a list of transliterations (i.e. ä/ae,ü/ue,ß/ss,â/a, etc.) seems to be beyond my skills.

Is there anything that I could use as a RegExp? The software uses the RegexKit framework.

Thanks, Helge.

link|improve this question
feedback

3 Answers

Two ways you could remove characters with diacritics in a shell script:

chars="äéėèêß○‡€"

echo -n "$chars" | iconv -c -f utf-8 -t us-ascii//TRANSLIT | tr -d "\"\`^'"
#=> aeeeessEUR

echo -n "$chars" | sed 's|ä|ae|g;s|ß|ss|g' | tr -C '\000-\200' '_'
#=> ae____ss___

Batch-renaming files after finding them recursively:

touch ~/Desktop/test\ {ää,öö}.txt
find ~/Desktop/ -maxdepth 1 -iname "test*" |
while read f; do
    mv "$f" "$(tr -C '\000-\200' '_' <<< "$f")"
done
link|improve this answer
feedback

There is already a way out in your situation: use several "rounds" of renaming, for each character.

Anyway, a single classical regex pattern is only a single case. You will need more expressive constructions in your renaming programming language to express what you want than just a regex pattern&replacement.

For example, sed (a standard Unix stream editor) allows to put several "substitute" commands (s) into one program (like this: s/a/AA/g;s/b/BB/g); they would be applied sequentially to each line of input. A Unix user with some scripting/shell skills could combine sed with file renaming commands to achieve what you want. Are you willing to learn some Unix shell?

link|improve this answer
Asked for help to complete my answer: <reddit.com/r/commandline/comments/mk7y4/…; -- write an elegant renaming command. – imz Nov 21 '11 at 15:46
feedback

An elegant Utility / Script to mass rename on the command line is the perl rename utility (see CPAN - http://search.cpan.org/~rmbarker/File-Rename-0.06/rename.PL its from Larry Wall).

My not so elegant use of this tool to rename the whole subtree of the current direcotry (all german umlauts in different (also broken UTF-8) encodings to ASCII) is :

find ./ -print0 | xargs -0 -L1 -I{} rename -n 's/ä/ae/g;s/ö/oe/g;s/ü/ue/g;s/Ö/Oe/g;s/Ü/Ue/g;s/Ä/Ae/g;s/ß/sz/g;s/\x75\xcc\x88/ue/g;s/\x61\xcc\x88/ae/g;s/\x6f\xcc\x88/oe/g;' "{}"

This prints out whats done. Remove the -n to get the real thing.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.