为解决批量转码的操作,使用了如下的脚本来进行。
#! /bin/sh convertCodeFilePath=$1 fromCode=$2 toCode=$3 for i in {1..1} do [ -f $convertCodeFilePath ] if [ $? -eq 0 ] then iconv -f $fromCode -t $toCode -c -o $convertCodeFilePath $convertCodeFilePath if [ $? -ne 0 ] then echo $convertCodeFilePath "=>" convert code failed. else echo $convertCodeFilePath "=>" convert code success. fi break; fi [ -d $convertCodeFilePath ] if [ $? -ne 0 ] then break; fi dir=`ls $convertCodeFilePath | sort -d` for fileName in $dir do fileFullPatch=$convertCodeFilePath/$fileName fileType=`echo $fileName |awk -F. '{print $2}'` [ -d $fileName ] if [ $? -eq 0 ] then continue fi if [ $fileType != 'sh' ] && [ $fileType != 'py' ] && [ $fileType != 'xml' ] && [ $fileType != 'properties' ] \ && [ $fileType != 'q' ] && [ $fileType != 'hql' ] && [ $fileType != 'txt' ] then continue fi iconv -f $fromCode -t $toCode -c -o $fileFullPatch $fileFullPatch if [ $? -ne 0 ] then echo $fileName "=>" convert code failed. continue else echo $fileName "=>" convert code success. fi done done
使用方式如下:
sh convertCode.sh /home/sam/data gbk utf-8
相关推荐
`iconv.exe`是`iconv`命令行工具的可执行文件,而`iconv.bat`则是一个批处理脚本,它调用`iconv.exe`并可能包含了一些预定义的参数和逻辑,以便用户更方便地使用转码功能。使用时,用户可能只需要在批处理文件中输入...
此时,我们可以编写Shell脚本来实现批量转码。以下是两个具体的例子: **例子一:** ```bash #!/bin/sh convertCodeFilePath=$1 fromCode=$2 toCode=$3 for i in {1..1} # 这里的{1..1}可能是一个错误,实际应用...
这篇文章主要介绍了编写shell脚本,使用iconv批量改变文件编码的脚本代码,需要的朋友可以参考下。 用法示例: cd ~/workspace/XXXProject ~/iconv_shell.sh ./ *java 好了,直接上代码~~ #!/bin/bash if [ $# != 2...
批处理脚本的工作原理是利用系统命令行工具,如`for`循环来遍历文件,然后调用文本编码转换工具(如`iconv`, `notepad++`的命令行模式NPPCMD,或者自定义的powershell脚本等)进行转换。转换过程通常包括读取源文件...
总的来说,通过结合Node.js的文件操作能力和`iconv-lite`的编码转换功能,我们可以编写出一个强大的工具,用于批量修改文件的编码格式。这个方法不仅可以应用于HTML和HTM文件,还可以扩展到其他类型的文本文件,只需...
上述脚本展示了通过bash脚本实现批量转换的方法。脚本首先定义了需要转换的文件类型(如.java, .xml, .html等),然后遍历当前目录及子目录下所有指定类型的文件。使用`iconv`命令进行编码转换,例如: ``` iconv ...
在上述过程中,如果CSV文件中的中文字符在导入时出现乱码问题,可以使用`iconv()`函数进行字符集转换,例如将`gb2312`转换为`utf-8`,以保证数据的正确显示。 文章中提到的示例代码展示了如何实现上述流程。一个...