Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: Find Locate Search Line Number String Keyword Text File udfGetLineOfStringInFile
AddExtender("wsrch34i.dll") path = "C:\Temp\" searchstring = "wsrch34i.dll" hand=SrchInit(path,"*.wbt",searchstring,"",0) filelist = '' While 1 a=SrchNext(hand) If a=="" Then Break filelist = ItemInsert(a, -1, filelist, @LF) EndWhile SrchFree(hand) Pause('',filelist)This code could be used to then locate the line numbers:
;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfGetLineOfStringInFile (strFilename, strSearch, intStart, intDirection, blnMatchCase) ; The FileGet version. If strSearch == "" Then Return 0 intFileSize = FileSize (strFilename) If intFileSize == 0 Then Return 0 If intStart < 1 Then Return 0 If intStart > intFileSize Then Return 0 strFile = FileGet (strFilename) If !!blnMatchCase intPos = StrIndex (strFile, strSearch, intStart, intDirection) Else intPos = StrIndexNC (strFile, strSearch, intStart, intDirection) EndIf If !!intPos Then Return 1 + StrCnt (strFile, @CRLF, 1, intPos, 1) Return 0 ;.......................................................................................................................................... ; Detlev Dalitz.20110716. ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ; Test. DirChange (DirScript ()) strFilename = IntControl (1004, 0, 0, 0, 0) ; We use this file as test input. strMsgTitle = "Demo: udfGetLineOfStringInFile" ; Test1. strSearch = "Test" intStart = 1 intLine = udfGetLineOfStringInFile (strFilename, strSearch, intStart, @FWDSCAN, @TRUE) If !!intLine strMsgText = StrCat ("String found: ", strSearch : @LF : "Line: ", intLine) Else strMsgText = StrCat ("String not found: ", strSearch) EndIf Message (strMsgTitle, strMsgText) ; Test2. strSearch = "Test" : 3 intStart = 1 intLine = udfGetLineOfStringInFile (strFilename, strSearch, intStart, @FWDSCAN, @TRUE) If !!intLine strMsgText = StrCat ("String found: ", strSearch : @LF : "Line: ", intLine) Else strMsgText = StrCat ("String not found: ", strSearch) EndIf Message (strMsgTitle, strMsgText) :CANCEL Exit
Article ID: W18363
Filename: Find Line Number of Keyword in a Text File.txt
File Created: 2011:07:18:07:24:52
Last Updated: 2011:07:18:07:24:52