I want to write a batch script that loops through the lines of a given file that contain a regular expression and then print out a substring of each result. Here is my script:
@echo off
pushd %~dp0
del /s /q output_var.txt
del /s /q output_a.txt
del /s /q output_final.txt
for /f "tokens=7 delims=|" %%a in ('findstr /r "AT=[A-Z]*_TABLE" "MyFile"') do (
set var=%%a
echo %var% >> output_var.txt
echo %%a >> output_a.txt
echo %var:~4% >> output_final.txt
)
popd
The regular expressions correctly pulls the strings that I am interested in based on the contents of output_a. However, output_var contains “ECHO is off.” and output_final contains “~4” when I would expect it to contain a substring after removing the first four characters. There appears to be an error with var=%%a
but the syntax looks correct to me based on my research.