Batch script: Analyze a log file

Solved
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

  • Votes
  • Date
  • Descending date
  1. 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.”
    1. If the files to be analyzed are too large, you might perhaps add a step to split them into smaller files.
  2. Contributor
    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?
    1. I could do it in C instead?
    2. 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!!!