Verifying the content of the read string from input file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Fredy
Posts: 1
Joined: 09 Sep 2009 08:24

Verifying the content of the read string from input file

#1 Post by Fredy » 09 Sep 2009 15:38

Hello,
I want to verify the content of the text read from the input file, before I transfer it to an out file.
I did try to put its content into a variable, but it doesn't work.
Some body can help me please?
Thanks.

for /F "tokens=1* delims=]" %%j in ('type "%param%" ^| find /V /N ""') do (
Set subStr=%%k:~0,12%%
)

However the following works:
for /F "tokens=1* delims=]" %%j in ('type "%param%" ^| find /V /N ""') do (
echo.%%k>> "OutputFile"
)

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#2 Post by avery_larry » 10 Sep 2009 08:50

substrings do not work on for variables (%%k). You have to assign a "normal" variable first and then do the substring.

Since you're inside a for loop, you'll have to use delayedexpansion like this:

*untested*

Code: Select all

@echo off
setlocal enabledelayedexpansion
for /F "tokens=1* delims=]" %%j in ('type "%param%" ^| find /V /N ""') do (
   set "tmpvar=%%~k"
   set "subStr=!tmpvar:~0,12!"
)


You could also do this without delayedexpansion:

Code: Select all

@echo off
for /F "tokens=1* delims=]" %%j in ('type "%param%" ^| find /V /N ""') do (
   set "tmpvar=%%~k"
   call set "subStr=%%tmpvar:~0,12%%"
)

Post Reply