2

I am trying to read two different fields per line of a file and assign those fields to two different variables so that I can work with both of the variables together in a for loop.

Right now I have

for /f "tokens=6 delims=:. " %%a in ('type %1% ^| findstr /R /V "Test"') do (
echo %%a
)

for /f "tokens=12 delims=:. " %%b in ('type %1% ^| findstr /R /V "Test"') do (
echo %%b
)

Is there anyway to combine them into something like

for /f "tokens=6,12 delims=:. " %%a %%b in ('type %1% ^| findstr /R /V "Test"') do (
echo %%a
echo %%b
)

Because right now this statement does not work.

1 Answer 1

5

This should work:

for /f "tokens=6,12 delims=:. " %%a in ('type "%~1" ^| findstr /R /V "Test"') do (
  echo %%a
  echo %%b
)

which could be simplified to

for /f "tokens=6,12 delims=:. " %%a in ('findstr /V "Test" "%~1"') do (
  echo %%a
  echo %%b
)

since findstr can read from files just fine, and you're not using a regular expression anyway.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.