How can I search through a file to check to see if there are two lines that start with the same characters?

At a command line in Windows, I want to search through a specific file and if it finds 2 instances of a line beginning with the same alphacharacters, then it needs to run a a specific vbs script.

For instance, in file located at c:\info\input.txt
Searching through the file,
If there are two lines in succession which start with DTM*, then it needs to run a cscript of 2.vbs, however if it finds
only 1 line starting with DTM* on it's own, then it needs to run 1.vbs.

What command line commands can I use to accomplish this?
Thanks.
100questionsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
This should do it; it's in test mode and will only display the csript commands; adjust lines 15 and 17 to your likings once you tested it successfully:
@echo off
setlocal enabledelayedexpansion
set InputFile=c:\info\input.txt
set FoundDouble=FALSE
set /a TestIndex = -1
for /f "tokens=1* delims=:" %%a in ('type "%InputFile%" ^| findstr.exe /n /r /i /c:"^DTM"') do (
	echo Line %%a: %%b
	if !TestIndex!==%%a (
		set FoundDouble=TRUE
	) else (
		set /a TestIndex = %%a + 1
	)
)
if %FoundDouble%==FALSE (
	ECHO cscript.exe /nologo "1.vbs"
) else (
	ECHO cscript.exe /nologo "2.vbs"
)

Open in new window

Edit: Forgot to ask: do you need to pass the file to analyze as command line argument, or can it remain hardcoded?
100questionsAuthor Commented:
Thank you.  It seems to search through the file well, however how can identify the path where 1.vbs and 2.vbs resides?  Currently I have both vbs files in the same folder however the vbs file is not executing.
Bill PrewIT / Software Engineering ConsultantCommented:
Do you only want to consider it a double if it is on the very next line, or could it be separated from the first by other lines?

~bp
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

oBdACommented:
Did you remove the ECHO at the beginning of the line?
And do you mean in the same folder as the batch script? Just use "%~dp0", which will expand to the batch script's current Drive and Path, with a trailing backslash:
@echo off
setlocal enabledelayedexpansion
set InputFile=c:\info\input.txt
set FoundDouble=FALSE
set /a TestIndex = -1
for /f "tokens=1* delims=:" %%a in ('type "%InputFile%" ^| findstr.exe /n /r /i /c:"^DTM"') do (
	echo Line %%a: %%b
	if !TestIndex!==%%a (
		set FoundDouble=TRUE
	) else (
		set /a TestIndex = %%a + 1
	)
)
if %FoundDouble%==FALSE (
	cscript.exe /nologo "%~dp01.vbs"
) else (
	cscript.exe /nologo "%~dp02.vbs"
)

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
100questionsAuthor Commented:
Thanks.
The vbs files are in a different path than the script, how can I modify the cscript to show the correct path where the vbs files reside?
oBdACommented:
Just set the path in lines 15 (for the 1 line scenario) and 17 (for the 2 lines scenario) after the "cscript.exe /nologo".
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.