DOS Batch Search for a string and move lines

June 15, 2011 at 02:16:53
Specs: Windows XP
DOS Batch search a string and move remaining lines to new file

Below is my original text file,

! Delimiter: ,
! Negative: -
! Scale: <NONE>
! Data View: Category
! Decimals: -1
! Suppress Options: Suppress All
! Extract Derived Value: Not Checked
! Conversion tables(Account): <NONE>
! Conversion tables(Entity): <NONE>
! Operation: <NONE>
! By: <NONE>
Act2011
4
4
LT,10083,73439
LT,10097,73439
LT,10011,3913
LT,10012,11
LT,10013,34784
LT,10014,408
LT,10015,97735


I want to search for string "ACT" from the above file and move the remining rest of lines to new file. So the new file will be looks like below

Act2011
4
4
LT,10083,73439
LT,10097,73439
LT,10011,3913
LT,10012,11
LT,10013,34784
LT,10014,408
LT,10015,97735


See More: DOS Batch Search for a string and move lines

Report •

#1
June 15, 2011 at 08:05:10
@echo off & setlocal EnableDelayedExpansion > "File.new"
for /F "delims=" %%a in ('type "File.txt"') do (
  set line=%%a
  if  /I "!line:~0,3!"=="ACT" set flag=ON
  if defined flag echo.%%a>> "File.new"
)


Report •
Related Solutions


Ask Question