Remove polish characters

Scenario
directory contains many files which names contain spaces and are in polish encoding, e.g.:
ls -1
ą ć.txt
Ą ź.txt
We want to rename these files into: 'a c.txt' and 'A z.txt'
Solution
write a bash script renaming each file separately:
bawi@hp:~$ cat rename.sh
#!/bin/bash

#remove spaces
r=$(echo $1 | sed 's/ /_/g')

#remove polish characters
r=$(echo $1 | sed 's/Ą/A/g' | sed 's/Ć/C/g' | sed 's/Ę/E/g' | sed 's/Ł/L/g' | sed 's/Ń/N/g' | sed 's/Ó/O/g' | sed 's/Ś/S/g' | sed 's/Ź/Z/g' | sed 's/Ż/Z/g' | sed 's/ą/a/g' | sed 's/ć/c/g' | sed 's/ę/e/g' | sed 's/ł/l/g' | sed 's/ń/n/g' | sed 's/ó/o/g' | sed 's/ś/s/g' | sed 's/ź/z/g' | sed 's/ż/z/g')

#to lower case
r=$(echo $1 | sed 's/JPG/jpg/g')
#r=$(echo $r | sed 's/JPG/jpg/g')

#echo '>>>' "$r" '<<>>' "$1" '|||' "$r" '<<<';
#mv "$1" "$r"

Then execute the script via:
find -name \*.txt -exec ./rename.sh "{}" \;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s