Copy/Extact lines from files inside folder, with a search word to a text file - windows batch

Most of windows systems writing log files into a file with the name of date and time stamp and all those files written inside the same folder .
But most in cases you might need to search a word or phrase within the files and check at what time or the line where this happens. The following batch script will help you to copy the lines from the files and write into another with the search word you given


@echo off
setlocal enableextensions
set “source=D:\logs\YOUR_FOLDER“
set “target=D:\logs\OUTPUT_FILE.txt“
pushd “%source%“
(for /f “tokens=1,* delims=:“ %%a in (‘ findstr /i /l /c:“SEARCH_WORD“ “*.Log“‘ ) do (
echo(%%b
)) > “%target%“
popd

You could replace YOUR_FOLDER,OUTPUT_FILE and SEARCH_WORD with your preference . enjoy

Rasika Preethiraj

A technophile at icrony since 2012, In a quest to programmatic automations for scaled organisations through the use of python, php, autoit and machine learning


Comments


Post a Comment



Trending

Latest Posts

Tags

Newsletter

Subscribe to our newsletter for good news, sent out every month.