Good day.
Need help: you need to write a script that would replace Russian letters in the file name, without touching the extension, in English (at least 3-4 letters).
Help me please!
Good day.
Need help: you need to write a script that would replace Russian letters in the file name, without touching the extension, in English (at least 3-4 letters).
Help me please!
If there are no Russian letters in the file extension, you can use the following method:
$ echo "привет" | sed 'y/рвт/rvt/' пrиvеt
The y/
streaming sed
command replaces the letters of the first group with the corresponding letters from the second.
If this functionality is not enough, there is always tr
.
tr Русские Нерусские
; done (the tr command with parameters must be enclosed in reverse apostrophes - who else would say how to type this in the comments) - alexlzIn addition to the first answer.
If this functionality is not enough, there is always tr.
Please note that tr
does not support unicode. Therefore, if the file names are in UTF-8, then tr
will not work.
The y / streaming sed command replaces the letters of the first group with the corresponding letters from the second.
If it is required, replace one Cyrillic letter with two Latin letters, then you can use the s
command. Several teams can be listed through ;
transliterate.sh
#!/bin/bash NEW=`echo "$1" | sed ' y/абвгдезийклмнопрстуфхцыАБВГДЕЗИЙКЛМНОПРСТУФХЦЫ/abvgdezijklmnoprstufhcyABVGDEZIJKLMNOPRSTUFHCY/; s/ё/yo/g; s/ж/zh/g; s/ч/ch/g; s/ш/sh/g; s/щ/shh/g; s/э/je/g; s/ю/ju/g; s/я/ja/g; s/Ё/YO/g; s/Ж/ZH/g; s/Ч/CH/g; s/Ш/SH/g; s/Щ/SHH/g; s/Э/JE/g; s/Ю/JU/g; s/Я/JA/g; s/[ъьЪЬ]//g'` mv -v $1 $NEW
$ ./transliterate.sh тест «тест» -> «test»
For batch renaming, you can use the find
find . -type f -name '*[а-яА-Я]*' -exec ./transliterate.sh {} \;
Source: https://ru.stackoverflow.com/questions/16396/
All Articles