回声“串” > Windows PowerShell中的文件将不可打印字符附加到文件 [英] echo "string" > file in Windows PowerShell appends non-printable character to the file

查看:309
本文介绍了回声“串” > Windows PowerShell中的文件将不可打印字符附加到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows PowerShell中:

echo "string" > file.txt

在Cygwin中:

$ cat file.txt
:::s t r i n g

$ dos2unix file.txt
dos2unix: Skipping binary file file.txt

我想要一个简单的字符串。我该怎么做?也就是说,当我说 cat file.txt 时,我只需要string作为输出。

I want a simple "string" in the file. How do I do it? I.e., when I say cat file.txt I need only "string" as output. I am echoing from Windows PowerShell and that cannot be changed.

推荐答案

尝试 echostring|我的回答从Windows PowerShell回声,不能更改。 out-file -encoding ASCII file.txt 以获取一个简单的ASCII编码的txt文件。

Try echo "string" | out-file -encoding ASCII file.txt to get a simple ASCII-encoded txt file.

echo "string" | out-file -encoding ASCII file.txt

将生成一个包含以下内容的文件:

will produce a file with the following contents:

73 74 72 69 6E 67 0D 0A (string..)

echo "string" > file.txt

将生成一个包含以下内容的文件:

will produce a file with the following contents:

FF FE 73 00 74 00 72 00 69 00 6E 00 67 00 0D 00 0A 00 (ÿþs.t.r.i.n.g.....)

(字节顺序标记FF FE表示文件是UTF-16(LE) :0xFF 0xFE后跟2个字节对​​xx 00 xx 00 xx 00正常0-127 ASCII字符

(Byte order mark FF FE indicates the file is UTF-16 (LE). The signature for UTF-16 (LE) = 2 bytes: 0xFF 0xFE followed by 2 byte pairs. xx 00 xx 00 xx 00 for normal 0-127 ASCII chars

这篇关于回声“串” > Windows PowerShell中的文件将不可打印字符附加到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆