LinuxCSH,将文本从utf-8文件复制到其他文件结果乱七八糟
我有带俄语字符的utf-8,我试图从中复制到新文件 但结果是乱七八糟的人物。 源文件可以在vim中打开并显示良好。 这是我剧本的一部分LinuxCSH,将文本从utf-8文件复制到其他文件结果乱七八糟,utf-8,csh,iconv,Utf 8,Csh,Iconv,我有带俄语字符的utf-8,我试图从中复制到新文件 但结果是乱七八糟的人物。 源文件可以在vim中打开并显示良好。 这是我剧本的一部分 # this is how i found in the internet to convert file to utf-8 set new_file_full_path = "/home/foo/env/output/test.csv" set f = "/home/foo/env/source/source_test.txt" if( ! -e $new_f
# this is how i found in the internet to convert file to utf-8
set new_file_full_path = "/home/foo/env/output/test.csv"
set f = "/home/foo/env/source/source_test.txt"
if( ! -e $new_file_full_path ) then
touch $new_file_full_path
iconv -f latin1 -t utf8 $new_file_full_path
endif
set new_line_buffer = ""
foreach line("`cat $source_dir/$f`")
#echo $line
if( $i > 14 ) then
echo "about to append to file"
echo $new_file_full_path
echo $line >> $new_file_full_path
echo "done append to file"
endif
@ i = $i + 1
end
我认为问题的一部分在于我这样做的时候:
目标文件
file -i /home/foo/env/output/test.csv
/home/foo/env/output/test.csv: text/plain; charset=unknown-8bit terminators
和源文件
file -i /home/foo/env/source/source_test.txt
text/plain; charset=utf-8
正如您所看到的,即使在我尝试转换它之后,目标文件也不是utf-8文件请注意,如果您希望在源文件和目标文件中保留utf-8,则不需要
iconv
iconv -f latin1 -t utf8 $new_file_full_path
在这里,您要求将文件/home/foo/env/output/test.csv
的拉丁1转换为UTF-8,结果将显示在stdout
中,因为您没有指定输出文件
我想你想要的是:
iconv -f utf8 -t latin1 $f -o $new_file_full_path
使用$f
将源文件转换为UTF-8格式,并在$new\u file\u full\u path
中转换为拉丁语,如果您需要的话。对不起,我没有意识到:可能不是您想要的目标文件编码:它不支持俄语字符。你可能想试试。顺便说一句,我不确定在endif
之后你在做什么。。。