不跳过批处理文件中的空行

简单的家伙

我正在尝试复制没有第一行的文件。但我似乎无法正确复制它的内容。

这是我尝试的方式:

for /f "tokens=* skip=1" %%i in (input.txt) do (
    echo %%i >> "output.txt"
)

当我的input.txt有这个时:

test1

1. test item1

2. test item2

3. test item3

它给了我这个:

1. test item1    
2. test item2
3. test item3

预期输出:

1. test item1

2. test item2

3. test item3

我如何实现这一目标?

麻古
@ECHO OFF
SETLOCAL
SET "sourcedir=U:\sourcedir"
SET "destdir=U:\destdir"
SET "filename1=%sourcedir%\q47067655.txt"
SET "outfile=%destdir%\outfile.txt"

(FOR /f "tokens=1*skip=1delims=:" %%a IN ('findstr /n /r ".*" "%filename1%"') DO ECHO(%%b)>"%outfile%1"
(FOR /f "tokens=1*skip=1delims=]" %%a IN ('find /n /v "" ^<"%filename1%"') DO ECHO(%%b)>"%outfile%2"
(more +1 "%filename1%">"%outfile%3")

GOTO :EOF

您需要更改 的设置sourcedir以适合您的情况。您需要更改的设置sourcedir,并destdir以适合你的情况。

我使用了一个名为q47067655.txt包含您的数据的文件进行测试。

生成定义为 %outfile%* 的文件

for /f 将跳过空行,因此通过编号确保行不为空。

请注意,这echo(%%a将产生一个空行%%a

您的示例输出省略了skipped 行和下一行之间的空行

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章