如何忽略 FOR 循环中文本文件处理行中特定单词后的所有行?
How to ignore all lines after a specific word on processing lines of a text file in a FOR loop?
我的问题是关于列而不是关于使用 skip=3
的行。这忽略了前 3 行。那么忽略下面示例中第一个 end
单词之后的所有行呢?
1121.19, 1638.66, 16.6098, -4.7339, -4.7339, 2.5, hash:0, -1, -1, -1, -1, 1888, 0, 0
971.597, 1815.17, 21.085, 1.39876E-006, 8, 4, hash:0, -1, -1, -1, -1, 1905, 0, 0
971.597, 1825.45, 21.085, 1.39876E-006, 8, 4, hash:0, -1, -1, -1, -1, 1905, 0, 0
end
tcyc
end
mlop
end
lodm
end
slow
end
blok
end
所以我想忽略所有不在我的基本格式中的行,即:
971.597, 1825.45, 21.085, 1.39876E-006, 8, 4, hash:0, -1, -1, -1, -1, 1905, 0, 0
需要哪些代码来忽略从第一个 end
单词到文件末尾的所有行,这将忽略示例输入中的以下行:
end
tcyc
end
mlop
end
lodm
end
slow
end
blok
end
这是我目前的代码:
if exist 12.txt del 12.txt
FOR /F "skip=3 tokens=1-8* delims=," %%A IN (C:\Users\Sherlock\DocumentsDReaperDX\Frames.txt) do >>12.txt echo model:%%H tx:%%A ty:%%C tz:%%B rx:%%D ry:%%F rz:%%E
第一个批处理文件检查 echo 行中使用的所有循环变量是否具有非空字符串,这会导致忽略除前 3 行之外的所有行。
@echo off
setlocal EnableExtensions
set "OutputFile=12.txt"
del "%OutputFile%" 2>nul
for /F "usebackq tokens=1-8* delims=," %%A in ("C:\Users\Sherlock\DocumentsDReaperDX\Frames.txt") do (
if "%%A" NEQ "" (
if "%%B" NEQ "" (
if "%%C" NEQ "" (
if "%%D" NEQ "" (
if "%%E" NEQ "" (
if "%%F" NEQ "" (
if "%%H" NEQ "" (
>>"%OutputFile%" echo model:%%H tx:%%A ty:%%C tz:%%B rx:%%D ry:%%F rz:%%E
)
)
)
)
)
)
)
)
endlocal
第二个批处理文件处理包含字符串 end
不区分大小写的第一行。
@echo off
setlocal EnableExtensions
set "OutputFile=12.txt"
del "%OutputFile%" 2>nul
for /F "usebackq tokens=1-8* delims=," %%A in ("C:\Users\Sherlock\DocumentsDReaperDX\Frames.txt") do (
if /I "%%A" EQU "end" goto ContinueAfterLoop
>>"%OutputFile%" echo model:%%H tx:%%A ty:%%C tz:%%B rx:%%D ry:%%F rz:%%E
)
:ContinueAfterLoop
endlocal
顺便说一句:如果用户帐户名称是 Sherlock
,%USERPROFILE%
与 C:\Users\Sherlock
相同。
我的问题是关于列而不是关于使用 skip=3
的行。这忽略了前 3 行。那么忽略下面示例中第一个 end
单词之后的所有行呢?
1121.19, 1638.66, 16.6098, -4.7339, -4.7339, 2.5, hash:0, -1, -1, -1, -1, 1888, 0, 0
971.597, 1815.17, 21.085, 1.39876E-006, 8, 4, hash:0, -1, -1, -1, -1, 1905, 0, 0
971.597, 1825.45, 21.085, 1.39876E-006, 8, 4, hash:0, -1, -1, -1, -1, 1905, 0, 0
end
tcyc
end
mlop
end
lodm
end
slow
end
blok
end
所以我想忽略所有不在我的基本格式中的行,即:
971.597, 1825.45, 21.085, 1.39876E-006, 8, 4, hash:0, -1, -1, -1, -1, 1905, 0, 0
需要哪些代码来忽略从第一个 end
单词到文件末尾的所有行,这将忽略示例输入中的以下行:
end
tcyc
end
mlop
end
lodm
end
slow
end
blok
end
这是我目前的代码:
if exist 12.txt del 12.txt
FOR /F "skip=3 tokens=1-8* delims=," %%A IN (C:\Users\Sherlock\DocumentsDReaperDX\Frames.txt) do >>12.txt echo model:%%H tx:%%A ty:%%C tz:%%B rx:%%D ry:%%F rz:%%E
第一个批处理文件检查 echo 行中使用的所有循环变量是否具有非空字符串,这会导致忽略除前 3 行之外的所有行。
@echo off
setlocal EnableExtensions
set "OutputFile=12.txt"
del "%OutputFile%" 2>nul
for /F "usebackq tokens=1-8* delims=," %%A in ("C:\Users\Sherlock\DocumentsDReaperDX\Frames.txt") do (
if "%%A" NEQ "" (
if "%%B" NEQ "" (
if "%%C" NEQ "" (
if "%%D" NEQ "" (
if "%%E" NEQ "" (
if "%%F" NEQ "" (
if "%%H" NEQ "" (
>>"%OutputFile%" echo model:%%H tx:%%A ty:%%C tz:%%B rx:%%D ry:%%F rz:%%E
)
)
)
)
)
)
)
)
endlocal
第二个批处理文件处理包含字符串 end
不区分大小写的第一行。
@echo off
setlocal EnableExtensions
set "OutputFile=12.txt"
del "%OutputFile%" 2>nul
for /F "usebackq tokens=1-8* delims=," %%A in ("C:\Users\Sherlock\DocumentsDReaperDX\Frames.txt") do (
if /I "%%A" EQU "end" goto ContinueAfterLoop
>>"%OutputFile%" echo model:%%H tx:%%A ty:%%C tz:%%B rx:%%D ry:%%F rz:%%E
)
:ContinueAfterLoop
endlocal
顺便说一句:如果用户帐户名称是 Sherlock
,%USERPROFILE%
与 C:\Users\Sherlock
相同。