Batch script: Analyze a log file

Solved
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


@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

barnabe0057 Posted messages 14329 Registration date   Status Contributor Last intervention   4 930
 
Hello, The first FOR is useless and contains an error, you can do it like this:
@echo off
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
-- “Artificial intelligence is defined as the opposite of natural stupidity.”
0
barnabe0057 Posted messages 14329 Registration date   Status Contributor Last intervention   4 930
 
If the files to be analyzed are too large, you might perhaps add a step to split them into smaller files.
0
yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   Ambassadeur 1 588
 
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?
0
poparnassus Posted messages 462 Status Member 31
 
I could do it in C instead?
0
yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   1 588 > poparnassus Posted messages 462 Status Member
 
If you know C, you could do it in C, indeed!
0
poparnassus Posted messages 462 Status Member 31
 
Yes I don’t know why I wanted to do it in Batch, I’m currently learning C, so this is going to be a perfect exercise on string manipulation!!!
0