Collect substring in each line of a file in CMD

3

That said, I wanted to go through a file.txt line by line and dump to another file each one of those lines taking away the first 9 characters and the last 2.

I have the following in a .bat but it does not work, do you see the error?

@echo off
cls
setlocal enabledelayedexpansion

for /F "tokens=*" %%a in (E:\Prueba\p3.txt) do (
    SET linea=%%a
    SET result= %linea:~9,-2%
    echo %result% >> "E:\Prueba\p1.txt"
)
pause

The p3.txt file contains something of this style:

:1004400002E00098401C00900A4900988842F8D3C6
:10045000002210210648FFF791FF0020009002E0E3
:100460000098401C0090034900988842F8D3E0E7C8
:1004700000100140A0860100880400080028002028
:08048000600200006C0100089D

At the exit I get:

ECHO está desactivado. 
    
asked by Estudiante 13.02.2017 в 09:19
source

1 answer

4

SOLVED!

The error was that within the for to detect the variables as such, they should be put between ! instead of % and use echo( instead of echo .

@echo off
setlocal enabledelayedexpansion

for /F "tokens=*" %%a in (E:\Prueba\p3.txt) do (
    SET linea=%%a
    SET result= !linea:~9,-2!
    echo(!result! >> "E:\Prueba\p1.txt"
)
pause
    
answered by 13.02.2017 в 10:15