get the line number that matches a specific text in a file

April 10, 2013 at 03:04:00
Specs: Windows 7
does someone know by the use of vbs the way to get the line number that matches a specific text in a file. (the text is send as a parameter). As example, i'd like to be able to say this text is on line eleven.

Please, don't take account that the text occurs more than once in file.

Thank for your answers


See More: get the line number that matches a specific text in a file

Report •

#1
April 10, 2013 at 03:54:06
:: ===== script starts here ===============
::
:: tamo.bat 2013-04-10 17:47:11.53
@echo off & setLocal enableDELAYedeXpansioN

for /f "tokens=1* delims=[]" %%a in ('find /n "%*" ^< myfile') do (
echo.%%a %%b
)
::====== script ends here =================

=====================
M2 Golden-Triangle


Report •

#2
April 10, 2013 at 17:45:06
"Please, don't take account that the text occurs more than once in file."
Er, I guess you mean just get the first instance of the string (in the case where there is more than one)?

And, do you want case-sensitive or ignore-case?

But I think M2's approach is probably the most efficient: just use "find" or "findstr" (either one will do, and either one can ignore case if politely asked to do so.)


Report •
Related Solutions


Ask Question