Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash: Convert non-ASCII characters to ASCII

Tags:

bash

ascii

How can I convert a string like Žvaigždės aukštybėj užges or äüöÖÜÄ to Zvaigzdes aukstybej uzges or auoOUA, respectively, using Bash?

Basically I just want to convert all characters which aren't in the Latin alphabet.

Thanks

like image 962
watain Avatar asked Dec 29 '09 14:12

watain


2 Answers

Depending on your machine you can try piping your strings through

iconv -f utf-8 -t ascii//translit 

(or whatever your encoding is, if it's not utf-8)

like image 145
Michael Krelin - hacker Avatar answered Oct 11 '22 18:10

Michael Krelin - hacker


You might be able to use iconv.

For example, the string:

Žvaigždės aukštybėj užges or äüöÖÜÄ

is in file testutf8.txt, utf8 format.

Running command:

iconv -f UTF8 -t US-ASCII//TRANSLIT testutf8.txt

results in:

Zvaigzdes aukstybej uzges or auoOUA

like image 22
Steve De Caux Avatar answered Oct 11 '22 17:10

Steve De Caux