使用 Powershell 的 UNIX 格式文件 [英] UNIX format files with Powershell
问题描述
如何在 Powershell 中创建 unix 文件格式?我正在使用以下内容创建一个文件,但它总是以 windows 格式创建它.
How do you create a unix file format in Powershell? I am using the following to create a file, but it always creates it in the windows format.
"hello world" | out-file -filepath test.txt -append
据我所知,新行字符 CRLF 使其成为 Windows 格式文件,而 unix 格式只需要行尾的 LF.我尝试用以下内容替换 CRLF,但没有用
As I understand, the new line characters CRLF make it to be a Windows format file whereas the unix format needs only a LF at the end of the line. I tried replacing the CRLF with the following, but it didn't work
"hello world" | %{ $_.Replace("`r`n","`n") } | out-file -filepath test.txt -append
推荐答案
一个难看的答案是(将输入从 dos.txt 输出到 unix.txt):
One ugly-looking answer is (taking input from dos.txt outputting to unix.txt):
[string]::Join( "`n", (gc dos.txt)) | sc unix.txt
但我真的很希望能够让 Set-Content 自己做这件事,这个解决方案不能流式传输,因此不能很好地处理大文件......
but I would really like to be able to make Set-Content do this by itself and this solution does not stream and therefore does not work well on large files...
而且这个解决方案也会以 DOS 行结尾来结束文件......所以它不是 100%
And this solution will end the file with a DOS line ending as well... so it is not 100%
这篇关于使用 Powershell 的 UNIX 格式文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!