如何保留 UNIX LF 行尾? [英] How can I keep UNIX LF line endings?

查看:61
本文介绍了如何保留 UNIX LF 行尾?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大 (9 GiB)、ASCII 编码、管道分隔的文件,带有 UNIX 样式的行结尾;0x0A.

I have a large (9 GiB), ASCII encoded, pipe delimited file with UNIX-style line endings; 0x0A.

我想将前 100 条记录抽样到一个文件中以供调查.以下将产生 100 条记录(1 条标题记录和 99 条数据记录).但是,它将行尾更改为 DOS/Winodws 样式;CRLF,0x0D0A.

I want to sample the first 100 records into a file for investigation. The following will produce 100 records (1 header record and 99 data records). However, it changes the line endings to DOS/Winodws style; CRLF, 0x0D0A.

Get-Content -Path .\wellmed_hce_elig_20191223.txt |
    Select-Object -first 100 |
    Out-File -FilePath .\elig.txt -Encoding ascii

我了解 iconv、recode 和 dos2unix.这些程序不在我的系统上,不允许安装.我已经搜索并找到了许多关于如何到达 CRLF 的地方.我没有找到任何关于到达或保持 LF 的信息.

I know about iconv, recode, and dos2unix. Those programs are not on my system and are not permitted to be installed. I have searched and found a number of places on how to get to CRLF. I have not found anything on getting to or keeping LF.

如何生成带有 LF 行结尾而不是 CRLF 的文件?

How can I produce the file with LF line endings instead of CRLF?

推荐答案

您可以将 Get-Content cmdlet 中的行与 Unix "`n" 换行符连接起来并保存.

You could join the lines from the Get-Content cmdlet with the Unix "`n" newline and save that.

类似的东西

((Get-Content -Path .\wellmed_hce_elig_20191223.txt | 
        Select-Object -first 100) -join "`n") |
        Out-File -FilePath .\elig.txt -Encoding ascii -NoNewLine

这篇关于如何保留 UNIX LF 行尾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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