.Bat file to Read Records from .txt file

September 26, 2010 at 00:15:58
Specs: Windows 7
Hi,

I am new to .Bat world , could you please help me to solve following Issue.

I will be having follwoing data in text file

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Incoming calls
call Start Timestamp: 2010-09-23-01.00.27.763505
Message INSERTED : 2
Message DELETED : 3
Message UPDATED : 1
call End Timestamp: 2010-09-23-01.20.28.418746

Incoming calls
call Start Timestamp: 2010-09-23-01.30.45.476361
Message INSERTED : 3
Message DELETED : 0
Message UPDATED : 1
call End Timestamp: 2010-09-23-01.57.45.752719

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I need to get Number of Incoming calls Per Hour (By counting Incoming calls)
Number of Message INSERTED Per Hour (End Time stamp )
Number of Message DELETED Per Hour (End Time stamp )
Number of Message UPDATED Per Hour(End Time stamp )


Using call End Time stamp first 8 characters are date(YYYY-MM-DD) remaning Time (HH:MM:SS:CC)

In Above Example Result looks like this
Number of Incoming calls Per Hour 1:00 : 2
Number of Message INSERTED Per Hour 1:00 :5
Number of Message DELETED Per Hour 1:00 :3
Number of Message UPDATED Per Hour 1:00 :2



See More: .Bat file to Read Records from .txt file

Report •

#1
September 27, 2010 at 00:13:25
Test this:

@echo off
cls
setlocal enabledelayedexpansion

for /f "skip=2 tokens=1-7* delims=-. " %%1 in (input.txt) do (
    set hour=%%7
        if !hour! lss 10 set /a hour=!hour:~-1!
    if /i %%2 equ inserted set input=%%4
    if /i %%2 equ deleted  set input=!input! %%4
    if /i %%2 equ updated  set input=!input! %%4
    if /i %%2 equ end (
          set input=!hour! !input!
          echo !input!>>%temp%\output!hour!.txt
          )
)

set nbr=0
set loops=0
:loop
if exist %temp%\output!nbr!.txt (
for /f "tokens=1-4" %%1 in (%temp%\output!nbr!.txt) do (
    set /a loops+=1
    set fil=%%1
    set /a outtwo=!outtwo!+%%2
    set /a outtre=!outtre!+%%3
    (set /a outfor=!outfor!+%%4
      >%temp%\outfil!fil!.txt echo !fil! !loops! !outtwo! !outtre! !outfor!)
      )

)
set outtwo=&set outtre=&set outfor=&set loops=

set /a nbr=!nbr!+1
if !nbr! gtr 23 (goto display)
goto loop
)

:display

set nbr=0
:loop2
if exist %temp%\outfil!nbr!.txt (
for /f "tokens=1-5" %%1 in (%temp%\outfil!nbr!.txt) do (
    echo Number of Incoming calls Per Hour %%1.00 : %%2
    echo Number of Message INSERTED Per Hour %%1:00 : %%3
    echo Number of Message DELETED Per Hour %%1:00 : %%4
    echo Number of Message UPDATED Per Hour %%1:00 : %%5
    echo.
))
    set /a nbr+=1
    if !nbr! gtr 23 (goto cleanup)
    goto loop2

:cleanup
del %temp%\outfil*.txt
del %temp%\output*.txt


Report •
Related Solutions


Ask Question