我如何使用sed linux命令处理Little-endian UTF-16文件 [英] how can I use linux command sed to process Little-endian UTF-16 file
问题描述
我正在开发有关Windows RDP的应用程序。现在,当我尝试使用sed命令直接在rdp文件中替换IP地址字符串时,我遇到了一个问题。但是执行此命令后,原始rdp文件会出现乱码。
I am working on an application about windows rdp. Now I get a problem when I try to use the sed command to replace the string of IP address directly in the rdp file. But after executing this command, the origin rdp file is garbled.
sed -i "s/address:s:.*/address:s:$(cat check-free-ip.to.rdpzhitong.rdp)/" rdpzhitong.rdp
我发现文件的格式为Little-endian UTF-16 Unicode。
I find that the file's format is Little-endian UTF-16 Unicode.
我仍然可以使用sed命令正确替换文件中的文本吗?还是其他解决此问题的方法?
Can I still use the sed command to replace the text in the files correctly? Or other method to process this problem?
推荐答案
如果文件是UTF-16编码的文本(如 RDP是),并且它不是您当前的编码(不太可能在Linux上),因此您可以预先使用 iconv
对文件进行后处理。例如:
If the file is UTF-16 encoded text (as RDP is), and that is not your current encoding (it's not likely to be on Linux) then you can pre- and post-process the file with iconv
. For example:
iconv -f utf-16 -t us-ascii <rdpzhitong.rdp |
sed 's/original/modified/' |
iconv -f us-ascii -t utf-16 >rdpzhitong.rdp.modified
这篇关于我如何使用sed linux命令处理Little-endian UTF-16文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!