Skip to main content

Posts

Showing posts from November 22, 2010

Batch file search for text and count lines

Hi all, I had just finish a batch file which will search for certain string in a file then count the number of lines with the string. Its great for searching through logfile. Points to take note: Remember to put Logfile.txt and countData.bat in the same folder. %1 is actually the value that the user can pass in. Logfile.txt is the file that you are searching in. There is 2 ways to get the batch file to work. One is type countData.bat "stringThatYouWantToSearch" in the command prompt. Second is create another batch file and type countData.bat "stringThatYouWantToSearch" in that batch file. Then double click on it to run it. Click Here for the Code with Megaupload or just copy the code below and paste it into a text file and rename it into countData.bat del sorted01.txt del count.txt type Logfile.txt| findstr /I/C:%1 >> sorted01.txt find /v /c "hahaharandomword" sorted01.txt >> count.txt echo -----------------------------