batch file - deleting content between lines containing certain words - in a text document -


i have huge text file , want delete portions of between 2 words. e.g:

lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis @ vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. mirum est notare quam littera gothica.

delete between "guis" , "gothica" words, becomes:

lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. ut wisi enim ad minim veniam, quis gothica.

actually in huge files there lots of "gui" s , "gothica" s , have rid of of them.

this can achieved simple batch script strange subject. tia if helps.

here simplest solution came with, i'm sure has issues things special characters, works given example. used filenames input.txt , output.txt.

@echo off setlocal disabledelayedexpansion set "flag=false" :: define lf contain newline character set lf=^   :: not remove above lines! > output.txt (     /f "eol= tokens=*" %%a in (input.txt) (         set "ln=%%a"         setlocal enabledelayedexpansion         %%l in ("!lf!") (             /f "eol= delims=., " %%w in ("!ln: =%%~l!") (                 if "%%w"=="quis" (                     set "flag=true"                     <nul set /p=%%w                  ) else if "%%w"=="gothica" (                     <nul set /p=%%w                      set "flag=false"                 ) else if "!flag!"=="false" (                     <nul set /p=%%w                  )             )         )         endlocal     ) ) 

this goes through each word , prints them out until finds quis, , resumes printing out after finds gothica. used <nul set /p=%%w echo without printing newline (see 2nd , 3rd links), has side effect of printing out space @ end of file, aware of that.

references:


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -