windows - Remove multi-line strings from a text file using a batch script -


I am trying to create a batch file that is to edit a text file to remove lines with a fixed string After this, an example of this file will look like:

line entry KEEP_1 delete the BLA BLA end line FOO bar end line entry REMOVE_2 Hello World end LINE KEEP_2 CAT DOG END

After running the batch script I े

 line entry KEPEPLALA BLA Endline key keeper2 cat DOGEND 

is required to include, where any row RicoVu has been removed, as well as related 'END 'Line.

I have tried to use techniques to remove stringed lines but it is unlikely that to include characters like \ r \ n and 'in search' END 'I call it 2 Can not do as separate FINDSTR commands because I still need 'end' text for 'two' entries.
Using findstr / v REMOVE_ leaves me with the following:

and using findstr / v "delete _ * \ r \ nEnd" does not seem to work at all, definitely to confirm each line \ R \ n ended with \ / code>.

Any help on this issue will be highly appreciated.

itemprop = "text">

The following batch script should be what you want:

  @ Echo off setlocal enabledelayedexpension set / a REMOVE_COUNT = 1 if "% ~ 2" == "" (echo experiment:% ~ n0 resides the search_str file lines, which contains a search_str and% REMOVE_COUNT% line ^ (s ^) directly After removing / Removal 1) Set "SEARCH_STR =% ~ 1" set "SRC_FILE =% ~ 2" / A for SKIP_COUNT = 0 / "leave = 2 delims = [] token = 1, *"% % I ('find / v / n' ""% SRC_FILE% "') (IF! SKIP_COUNT! EQU 0 (SRC_LINE = %% J is set if SRC_LINE line (If "! SRC_LINE:% SEARCH_STR% =!" == "! SRC_LINE!" (Echo!! SRC_LINE!) And (set / one SKIP_COUNT =% REMOVE_COUNT%)) Others (RIM SRC_LINE is empty echo. )) Other (set / A SKIP_COUNT- = 1))  

Configure the number of lines to be removed after a matching line by setting the REMOVE_COUNT variable .

Using a script, the file is arranged correctly with the empty rows: the order of finding all the lines with the line numbers. In such a way, the blank lines will not be used for the command.


Comments