小编cod*_*rE1的帖子

如何使用批处理或PowerShell从文本文件中删除换行符

本质上,我想从file.txt中读取内容

苹果
香蕉
胡萝卜

并写入newfile.txt,使其包含内容

苹果香蕉胡萝卜

我需要在没有安装权限的Windows计算机上执行此操作。

我试过了

set row=
for /f %%x in (file.txt) do set row=%row% %%x
echo row > newfile.txt
Run Code Online (Sandbox Code Playgroud)

并且我尝试使用PowerShell语句(无法运行PowerShell脚本)而不是CMD样式的for循环。

powershell -Command "(Gc file.txt) | Foreach-Object -Process {set row=%row% _$} | Out-File newFile.txt"
Run Code Online (Sandbox Code Playgroud)

但都产生一个空文件。有没有办法做到这一点?

string powershell file-io cmd batch-file

3
推荐指数
1
解决办法
5714
查看次数

标签 统计

batch-file ×1

cmd ×1

file-io ×1

powershell ×1

string ×1