我有这个脚本:
@ECHO OFF
(FOR /f tokens^=2^ delims^=^" %%a IN ('findstr /l "\<SOMETHING=\>" FILE.vav') DO (Echo | Set /p =%%a,)) >> Results.txt
现在结果如下:
SOMETHING, SOMETHING, SOMETHING, SOMETHING, SOMETHING, SOMETHING, SOMETHING, SOMETHING, SOMETHING, SOMETHING, SOMETHING, SOMETHING, SOMETHING,
..但我需要在每5个结果后插入空行,因此结果应如下所示:
SOMETHING, SOMETHING, SOMETHING, SOMETHING, SOMETHING,
//blank line
SOMETHING, SOMETHING, SOMETHING, SOMETHING, SOMETHING,
// blank line
SOMETHING, SOMETHING, SOMETHING,
伙计们,请帮帮我吧?我没希望了..
可能解决方案是FOR /L
和IF
,但我无法理解。
提前谢谢你,Jakub
答案 0 :(得分:3)
试试这个:
ECHO OFF &SETLOCAL
(FOR /f tokens^=2^ delims^=^" %%a IN ('findstr /l "\<SOMETHING=\>" FILE.vav') DO (
<NUL Set /p =%%a,
SET /a counter+=1
SETLOCAL ENABLEDELAYEDEXPANSION
SET /a counter%%=5
IF !counter! equ 0 ECHO(
ENDLOCAL
)
)>Results.txt
TYPE results.txt
答案 1 :(得分:0)
比这里呈现的(Endoro完全回答)
我希望显示一个解决方案,用于在读入的文件中插入空行:
@Echo off&SetLocal EnableDelayedExpansion
Set "File=%~1" & If not defined File (Echo No file name passed&Pause&Exit /B 1)
Set n=2
for /F "delims=" %%A in (
'Findstr "^" %FILE%'
) do (
Echo:%%A
set /A "#+=1,#%%=n" & If !#!==0 Echo:
)
一个非常类似的处理另一个命令的输出,
此处sc
已过滤findstr
:
@Echo off&SetLocal EnableDelayedExpansion
Set n=2
for /F "delims=" %%A in (
'sc query ^| findstr "SERVICE_NAME DISPLAY_NAME"'
) do (
Echo:%%A
set /A "#+=1,#%%=n" & If !#!==0 Echo:
)
n
不言而喻。#
计算行数,模数由n
划分,如果为零则发出所需的空白行。!
输出中的感叹号被删除。