Simply use FINDSTR with an appropriate regex search string. Do it once to move matching lines, and a 2nd time with /V option to move non-matching lines. It might seem less efficient because each file is read twice. But in reality it will be much faster than any FOR /F loop.
To truly move the line, you should also either delete the original file when done, or at least move the original file to a new location. That way you can re-run your batch script the next day and not get confused by prior day's files.
It is important that the destination files reside in a different folder than the source so as not to mistakenly process the destination files as source material.
Code: Select all
@echo off
setlocal
set "chars=ABCDE"
set "sourceMask=sourcePath\*.txt"
set "matchOutput=destinationPath\match.txt"
set "noMatchOutput=destinationPath\noMatch.txt"
for %F in ("%sourceMask%") do (
findstr /r "^.........[%chars%]" "%F" >"%matchOutput%"
findstr /rv "^.........[%chars%]" "%F" >"%noMatchOutput%"
REM - I recommend DEL "%F" or MOVE "%F" "newLocation"
)
Dave Benham