Question:
In Windows PowerShell:
1 2 |
echo "string" > file.txt |
In Cygwin:
1 2 3 4 5 6 |
$ cat file.txt :::s t r i n g $ dos2unix file.txt dos2unix: Skipping binary file file.txt |
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.
Answer:
Try echo "string" | out-file -encoding ASCII file.txt
to get a simple ASCII-encoded txt file.
Comparison of the files produced:
1 2 |
echo "string" | out-file -encoding ASCII file.txt |
will produce a file with the following contents:
1 2 |
73 74 72 69 6E 67 0D 0A (string..) |
however
1 2 |
echo "string" > file.txt |
will produce a file with the following contents:
1 2 |
FF FE 73 00 74 00 72 00 69 00 6E 00 67 00 0D 00 0A 00 (ÿþs.t.r.i.n.g.....) |
(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