如何.txt使用简单的 cmd 命令从文件中删除换行符?
这将删除文件:
findstr "{\r\n}" %USERPROFILE%\Desktop\tt\t.txt %USERPROFILE%\Desktop\tt\t.txt > t.txt
Run Code Online (Sandbox Code Playgroud)而这将添加无用的信息:
findstr "." %USERPROFILE%\Desktop\tt\t.txt %USERPROFILE%\Desktop\tt\t.txt > t.txt
Run Code Online (Sandbox Code Playgroud)您指定了两次输入文件,因此您将数据加倍。
如果目的是删除空行,那么您离正确的命令不远了:
findstr "." "%USERPROFILE%\Desktop\tt\t.txt" > t.txt
Run Code Online (Sandbox Code Playgroud)
只需确保您的当前文件夹不是%USERPROFILE%\Desktop\tt,否则您将覆盖输入文件。您也可以为输出文件指定完整路径。
以下帖子可能也有帮助:
如何使用批处理或 PowerShell 从文本文件中删除换行符。
为了完全删除所有换行符,我使用了以下脚本:
@echo off
setlocal EnableDelayedExpansion
set row=
for /f %%x in (test.txt) do set "row=!row!%%x"
echo %row% >newfile.txt
echo %row%
Run Code Online (Sandbox Code Playgroud)
以下是运行上述脚本的工作原理:
| 归档时间: |
|
| 查看次数: |
6399 次 |
| 最近记录: |