Find a term and remove it, from many files
Moderator: DosItHelp
Find a term and remove it, from many files
Hi, My requirement is i have to find a word 'Grants' In many text files and delete the entire line containing 'Grants'. But i need to do In many text files at a time. How can this be achieved
Re: Find a term and remove it, from many files
Give this a whirl:
Code: Select all
@echo off
for /f "delims=" %%a in (' dir *.txt /b /a-d ') do find /v "Grants" < "%%a" >"%%~na-new%%~xa"
Re: Find a term and remove it, from many files
Similar to foxidrive's solution, except uses FINDSTR with regex and word boundry anchors. Also effectively edits the files instead of creating new modified copies.
Add the /I switch if you want the search to be case insensitive.
Dave Benham
Code: Select all
@echo off
for /f "delims=" %%F in (' dir *.txt /b /a-d ') do (
findstr /v "\<Grants\>" "%%F" >"%%F.new"
move /y "%%F.new" "%%F" >nul
)
Add the /I switch if you want the search to be case insensitive.
Dave Benham