Can anybody help me in making the windows batch file to find the substring from the log file. Sample of the log.log file is as below
ID,Date,Time,Description,IP Address,Host Name,MAC Address
10,02/21/14,00:29:45,Assign,172.20.55.50,PC1,123456789AB1,
31,02/21/14,00:29:45,DNS Update,172.20.55.50,PC1,123456789AB1,
10,02/21/14,00:29:45,Assign,172.30.55.50,PC2,123456789AB2,
31,02/21/14,00:29:45,DNS Update,172.30.55.50,PC1,123456789AB2,
10,02/21/14,00:29:45,Assign,172.20.56.60,PC3,123456789AB3,
10,02/21/14,00:29:45,Assign,172.30.55.60,PC4,123456789AB4,
**11,02/21/14,00:30:45,Assign,172.30.55.10,PC2,123456789AB5,**
**11,02/21/14,00:30:46,Assign,172.30.55.10,PC2,123456789AB5,**
**31,02/21/14,00:00:37,DNS Update Failed,172.17.110.13,TAR-CAR-051180L.WTPK.local,-1,**
This is basically DHCP log file. The objective is to count number of New Assign IP requests (whose ID is 10) and number of renewal IP requests (whose ID is 11).
For ID 10, if the IP starts with 172.20.55 or 172.20.56 it should increment in the counter "NewPoolA" and if the IP starts with 172.30.55 or 172.30.56 it should increment in "NewPoolB".
Similarly for ID 11 if the IP starts with 172.20.55 or 172.20.56 it should increment in the counter "RenewPoolA" and if the IP starts with 172.30.55 or 172.30.56 it should increment in "RenewPoolB".
so far what I have done is below
@echo off
Setlocal EnableDelayedExpansion
set /a NewPoolA=0
set /a NewPoolB=0
set /a RenewPoolA=0
set /a RenewPoolB=0
for /F "tokens=1-6 delims=," %%a in (log.log) do (
if %%a equ 10 (
rem if %%e contains 172.20.55 (
set /a NewPoolA += 1
goto someLabel
)
rem else if %%e contains 172.20.56 (
set /a NewPoolA += 1
goto someLabel
)
rem else if %%e contains 172.30.55 (
set /a NewPoolB += 1
goto someLabel
)
rem else if %%e contains 172.30.56 (
set /a NewPoolB += 1
goto someLabel
)
rem -------- if id 10 and not match any condition then
goto someLabel
) else if %%a equ 11 (
rem if %%e contains 172.20.55 (
set /a RenewPoolA += 1
goto someLabel
)
rem else if %%e contains 172.20.56 (
set /a RenewPoolA += 1
goto someLabel
)
rem else if %%e contains 172.30.55 (
set /a RenewPoolB += 1
goto someLabel
)
rem else if %%e contains 172.30.56 (
set /a RenewPoolB += 1
goto someLabel
)
rem -------- if id 11 and not match any condition then
goto someLabel
)
)
echo Total new request in Pool A is %NewPoolA%
echo Total renewal request in Pool A is %RenewPoolA%
echo Total new request in Pool B is %NewPoolB%
echo Total renewal request in Pool B is %RenewPoolB%
This is the logic and my understanding that how it will work. I dont know the syntax of dos batch commands.
These two pools are just example. I have total 80 pools for which i have to do this. In log file there are almost 100,000 entries. To match this number of lines to each of the pool will take too much time. So, the goal is to jump out of the 'if condition' after incrementing the value and to shorten the execution time of the batch file.
One more thing, the log file contains duplicate entries in different timings for same mac address. I need the increment will run only for unique entries of mac address.