使用 bash 中的 iconv 更改编码多个文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16600835/
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 05:27:24  来源:igfitidea点击:

Change encoding multiple file with iconv in bash

bashencodingiconv

提问by Danil Chernokalov

I want to change multiple php files encoding with iconv.

我想用 iconv 更改多个 php 文件编码。

I use find and exec option (Reference : http://linux.bigresource.com/Ubuntu-Encoding-Conversion-on-Multiple-Files--4fuXvUwbN.html)

我使用 find 和 exec 选项(参考:http: //linux.bigresource.com/Ubuntu-Encoding-Conversion-on-Multiple-Files--4fuXvUwbN.html

find . -type f -name '*.php' -print -exec iconv -f euc-kr -t utf-8 {} -o {}.utf8 

But the error is occured.

但是出现了错误。

find: missing argument to `-exec'

I just want to convert all php files in a once time. How can i do this with one statement in a bash?

我只想一次转换所有 php 文件。我怎样才能在 bash 中用一个语句来做到这一点?

回答by John Kugelman

You must put either \;or +at the end of the -execaction.

您必须将\;+放在-exec动作的末尾。

find . -type f -name '*.php' -print -exec iconv -f euc-kr -t utf-8 {} -o {}.utf8 \;

回答by klaun

after some tests finally found out solution working on my mac

经过一些测试,终于找到了适用于我的 mac 的解决方案

for f in *.TXT; do iconv -f CP1250 -t utf-8 $f > $f.txt; done