Batch script: Analyze a log file
Solved
poparnassus
Posted messages
462
Status
Member
-
poparnassus Posted messages 462 Status Member -
poparnassus Posted messages 462 Status Member -
Hello,
Hi MessieuDame :-)
So I need to analyze a set of log files that contains ~1,000,000 lines (and probably much more, since I can’t even determine the exact number ^^). I tried testing a batch script but it freezes at the second file with 364,000 lines, just for the line count LOL
So what would you recommend? C code? more performant?
I’m looking for IP addresses different from the local network, so I want to list all addresses that are not in 192.168.xxx.xxx
Below is the code used to count the lines.
Thanks for not insulting me, I know batch is far from being performant lol
Best regards and have a good evening
Configuration: Windows / Chrome 58.0.3029.110
Hi MessieuDame :-)
So I need to analyze a set of log files that contains ~1,000,000 lines (and probably much more, since I can’t even determine the exact number ^^). I tried testing a batch script but it freezes at the second file with 364,000 lines, just for the line count LOL
So what would you recommend? C code? more performant?
I’m looking for IP addresses different from the local network, so I want to list all addresses that are not in 192.168.xxx.xxx
Below is the code used to count the lines.
Thanks for not insulting me, I know batch is far from being performant lol
Best regards and have a good evening
@echo off
SETLOCAL enableextensions ENABLEDELAYEDEXPANSION
@for %%n in (%0) do set fold=%%~dpn
::path
set archive=%fold%Archive_LOG\local
echo %archive%
pause
::Line counter for log files
cd %archive%
set /a total=0
for %%A in (*.txt) do (
set /a compt=0
for /f "tokens=*" %%I in ('type "%%A"') do (set /a compt+=1)
echo %%~dpnxA : !compt!
set /a total=!total!+!compt!
)
echo. & echo Total lines : !total!
Configuration: Windows / Chrome 58.0.3029.110
2 answers
-
Hello, The first FOR is useless and contains an error, you can do it like this:
@echo off
-- “Artificial intelligence is defined as the opposite of natural stupidity.”
setlocal enableextensions enabledelayedexpansion
set archive=%~dp0Archive_LOG\local
echo %archive%
echo.
::Line counter for log files
cd %archive%
set /a total=0
for %%A in (*.txt) do (
set /a compt=0
for /f "tokens=*" %%I in ('type "%%A"') do (set /a compt+=1)
echo %%~nxA : !compt!
set /a total=!total!+!compt!
)
echo. & echo Total lines : !total!
echo. & pause
exit -
Hello, why count the lines if you’re looking for IP addresses?
why did you choose to do it this way, what other tools do you master?