Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unaccent string in bash script (RHEL)

Tags:

bash

iconv

On Debian-based distributions, there is a utility called unaccent which can be used to remove accents from accented letters in a text.

I was looking for a package containing this on Redhat distros, but the only one I found was unac available for Mandriva only.

I tried to use iconv but it seems to not support my case.

What is the best, lightweight approach, easily usable in a bash script ? Are there any secret options to iconv that allow this ?

like image 202
Petr Kozelka Avatar asked Mar 27 '12 12:03

Petr Kozelka


1 Answers

You can use the -c(clear) option in iconv to remove non-ascii chars:

$ echo 'été' | iconv -c -f utf8 -t ascii
t

If you just want to remove the accent:

$ echo 'été' | iconv -f utf8 -t ascii//TRANSLIT
ete
like image 197
kev Avatar answered Sep 18 '22 18:09

kev