当前位置: 动力学知识库 > 问答 > 编程问答 >

windows - Findstr command in for-loop stops after a certain line

问题描述:

I have this snippet of script:

for /F "tokens=1* delims=:" %%a in ('findstr /N /C:"%SECTION%" /C:"%TARGET%" %BASE%') do (

:: Stuff:

)

echo Search Parameters not found

...where SECTION and TARGET are two search parameters. The BASE file is approximately 16,000 lines.

Here's my problem:

When I execute the for-loop inside a batch script, it searches for 2397 lines exactly, then just gives up. However, if I run the findstr command manually, it will search all lines as expected.

Any ideas?

网友答案:

Does this fail for you? It works here in Win 8 and a XP Pro VM to print 16,000 lines.

@echo off
(for /l %%a in (1,1,16000) do @echo 0123456789012345678901234567890123456789)>file
SET "section=123"
SET "target=456"
SET "base=file"

ECHO start
for /F "tokens=1* delims=:" %%a in ('findstr /NC:"%SECTION%" /C:"%TARGET%" "%BASE%"') do (
ECHO %%a
)
pause
网友答案:

Fool's mistake - upon changes of versions, the location of a certain file shifted. So while I thought my search for the file was correct, it actually ended up retrieving a file in similar name, but not the same file (MotionBase.class.asasm vs what I needed: BASE.class.asasm) Thought I checked the location before submitting this question, but apparently not.

分享给朋友:
您可能感兴趣的文章:
随机阅读: