bash 脚本中的非重音字符串 (RHEL)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9889428/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 01:52:11  来源:igfitidea点击:

Unaccent string in bash script (RHEL)

bashiconv

提问by Petr Kozelka

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

在基于 Debian 的发行版上,有一个名为unaccent的实用程序,可用于从文本中的重音字母中删除重音。

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

我一直在 Redhat 发行版上寻找包含此内容的软件包,但我找到的唯一一个是unac仅适用于 Mandriva。

I tried to use iconvbut it seems to not support my case.

我尝试使用iconv但它似乎不支持我的情况。

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

什么是最好的、轻量级的、易于在 bash 脚本中使用的方法?iconv 是否有任何允许这样做的秘密选项?

回答by kev

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

您可以使用-c(clear) 选项iconv删除非 ascii 字符:

$ 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