1

In my .bat file below I am getting the following results.

@echo off
set result=""
set filteredResult=""
setlocal enabledelayedexpansion
FOR /F "tokens=* delims=" %%x in (outputText.txt) DO (SET result=%%x & SET  filteredResult=%result:~0,5% & echo !filteredResult!)
pause

outputText.txt

tables
--------------------------
number one
number two
number three
(3) lines

Results

""
""
""
""
""
""
Press any key to continue . . .

Why am I not getting a substring of 5 from result.?

Darren
  • 1,352
  • 5
  • 19
  • 49

1 Answers1

1

You should replace % to ! filteredResult=%result:~0,5% to filteredResult=!result:~0,5!

@echo off
set result=""
set filteredResult=""
setlocal enabledelayedexpansion
FOR /F "tokens=* delims=" %%x in (outputText.txt) DO (SET result=%%x & SET  filteredResult=!result:~0,5! & echo !filteredResult!)
pause
Hackoo
  • 18,337
  • 3
  • 40
  • 70