1.

Solve : bat file to search a file and form new reports from the file?

Answer»

Hi i have a log.txt file which has multiple entries like below


Message to the mobile no [ mnumber=9623434524 not sent ].failed
something somethingXXXX xXXX
Message to the mobile no [ Recieved Acknowledgement for mnumber=98373458938 ]
Message to the mobile no [ mnumber=962342345324 not sent ].failed
something somethingXXXX xXXX
Message to the mobile no [ mnumber=96234432454 not sent ].failed
Message to the mobile no [ Recieved Acknowledgement for mnumber=9543448938 ]



I want a BAT file to READ this log file for lines with keywords ".failed" and "[Recieved Acknowledgement".

then from each LINE with keyword ".failed" it should find the substring "mnumber=98987676765" and save in a file failedreport.txt
similarly
from each line with keyword "[Recieved Acknowledgement" it should find the substring "mnumber=989873453345" and save in a file succesreport.txt

the log file is at location c:\Application\logs
reports can be MADE at c:\Application\reports
all mnumbers are differnt but only 10 digits
mnumbers will be SURELY present in line with keywords ".failed" and "[Recieved Acknowledgement".

can this be done ..
pleas help .

aditya Note correct spelling of "Received". Is this as it appears in log.txt?

sorry its "Received" ..... my mistake...Note "success" is spelt thus...

Code: [Select]@echo off
for /f "tokens=1-26 delims== " %%A in (log.txt) do (
if "%%G"=="Received" echo %%J=%%K >> c:\Application\reports\successreport.txt
if "%%G"=="mnumber" echo %%G=%%H >> c:\Application\reports\failedreport.txt
)



Discussion

No Comment Found