Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: Count Keywords in Several Files
Sam Bob Frank etc...The next log file might have the names or different name such as Ryan, Brooke, Tammy etc... I need a count of how many times each name might show up in all the log files. So I would have 20 log files and Bob would show up 10 times (Bob = 10) (Tammy = 5) etc... How would I do this? Thanks for all the great help!!
Bob=0 Frank=0 Ted=0 Tammy=0 DirChange("C:\TEMP\Names") allfiles=FileItemize("*.txt") count=ItemCount(allfiles,@tab) for i=1 to count eachfile=ItemExtract(i,allfiles,@tab) ; Find number of Bob, Frank, Ted, Tammy in eachfile fs1 = FileSize(eachfile) binbuf1 = binaryalloc( fs1 ) BinaryRead( binbuf1, eachfile) Bob= Bob+BinaryStrCnt( binbuf1, 0, fs1 - 1, "Bob") Frank= Frank+BinaryStrCnt( binbuf1, 0, fs1 - 1, "Frank") Ted= Ted+BinaryStrCnt( binbuf1, 0, fs1 - 1, "Ted") Tammy= Tammy+BinaryStrCnt( binbuf1, 0, fs1 - 1, "Tammy") BinaryFree( binbuf1 ) next Message( "Totals are:", "Bob count=%Bob%%@crlf%Frank count=%Frank%%@crlf%Ted count=%Ted%%@crlf%Tammy count=%Tammy%" )Otherwise, if there are multiple unknown names, you could do something like:
DirChange("C:\incoming") list=Fileitemize("*.log") count=ItemCount(list,@tab) datafile="c:\incoming\datafile.ini" IniDeletePvt("UserCounts",@WHOLESECTION,datafile) for xx=1 to count thisfile=ItemExtract(xx,list,@tab) handle=FileOpen(thisfile,"READ") while 1 line=FileRead(handle) if line == "*EOF*" then break line=Strlower(line) ; run in lowercase usercount=IniReadPvt("UserCounts",line,0,datafile) IniWritePvt("UserCounts",line,usercount+1,datafile) endwhile FileClose(handle) next IniWritePvt("","","",datafile) Message("All Doned","See datafile.ini")
Article ID: W14590
Filename: Count Keywords in Several Files.txt
File Created: 2000:09:27:15:11:00
Last Updated: 2000:09:27:15:11:00