parsing log files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
joe
Posts: 35
Joined: 06 Sep 2017 07:56

parsing log files

#1 Post by joe » 14 Dec 2017 08:53

hi

I have 100's of .log files in a folder E:\logs

my request is for a batch file that reads a keywords.txt file
the keywords.txt file contain 2 column
1 keyword to search for and 2 corresponding folder to be created.

ie..

MBD MOTHERBOARD
RAM MEMORY
HDD HARDDRIVE
AUDIO SOUNDCARD
........and so on

the batch file should search .log files for keywords and then create corresponding folder mentioned against each keyword
and copy the .log files to them

source directory E:\logs
destination directory g:\sorted

please help me..
thanx in advance..

joe

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: parsing log files

#2 Post by aGerman » 14 Dec 2017 10:26

Code: Select all

@echo off &setlocal
set "listfile=keywords.txt"
set "source=E:\logs"
set "destination=g:\sorted"

for /f "tokens=1,2" %%i in ('type "%listfile%"') do (
  for /f "tokens=1,2 delims=:" %%k in ('findstr "\<%%i\>" "%source%\*.log"') do (
    2>nul md "%destination%\%%j"
    copy "%%k:%%l" "%destination%\%%j\"
  )
)
If you want to apply a case-insensitive search then add option /i to the findstr command.

Steffen

joe
Posts: 35
Joined: 06 Sep 2017 07:56

Re: parsing log files

#3 Post by joe » 15 Dec 2017 06:52

this code worked perfectly

thank you steffen for taking so much of you valuable time :P

Post Reply