Find String in dos based on it's position

May 12, 2009 at 08:56:23
Specs: Windows XP
I have a batch file that searchs for the string "ERROR". My problem is I need to just find the lines where "ERROR" is the first 5 characters of that line. I have "ERROR" in other places such as notes within my file that I don't need to see. Is it possible to check columns of my file to see if the first 5 containt "ERROR".

Thank You

See More: Find String in dos based on its position

Report •

May 12, 2009 at 14:17:58

@echo off
setlocal EnableDelayedExpansion
for /f "tokens=* delims=" %%a in (error.txt) do (
set Line=%%a
set Err=!Line:~,5!
if /i "!Err!"=="ERROR" (echo %%a)

Report •

May 13, 2009 at 03:44:04
findstr "^ERROR" file.txt

Report •

Related Solutions

Ask Question