Page 1 of 1

parsing log files

Posted: 14 Dec 2017 08:53
by joe
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

Re: parsing log files

Posted: 14 Dec 2017 10:26
by aGerman

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

Re: parsing log files

Posted: 15 Dec 2017 06:52
by joe
this code worked perfectly

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