windows - Using a batch program to search for a keyword and copy offset content to a file -


i trying figure out way code windows batch program search file keyword. every time keyword found, line 3 lines below content found, , letter 5 12 copied file. using example input file below:

example_input.txt  bla bla bla bla bla bla bla bla bla bla bla keyword bla bla bla bla bla bla bla bla bla bla bla bla bla content1bla bla bla keyword bla bla bla bla bla bla bla bla bla bla bla bla bla content2bla bla 

i wish following output file

example_ouput.txt  content1 content2 

the input file never have keyword before content offset reached. may necessary copy multiple content items per keyword.

i have searched , found couple of single elements of process, have been unable combine these working script. therefore highly appreciate help.

i wrote efficient program called findrepl.bat designed find strings in files in advanced ways. use straightforward, can see in example session below:

c:\> type input.txt bla bla bla bla bla bla bla bla bla bla bla keyword bla bla bla bla bla bla bla bla bla bla bla bla bla content1bla bla bla keyword bla bla bla bla bla bla bla bla bla bla bla bla bla content2bla bla  c:\> rem use findrepl, redirect input file , insert search word:  c:\> < input.txt findrepl "keyword" bla keyword bla bla bla keyword bla bla  c:\> rem /offset switch allows define blocks of lines based on found lines:  c:\> < input.txt findrepl "keyword" /o:+3:+3 bla content1bla bla bla content2bla bla  c:\> rem evaluate regular expression on such /block of lines c:\> rem , show matched subexpression enclosed in parentheses via /$ switch c:\> rem (the regexp format described in noodlesstillalive answer above)  c:\> < input.txt findrepl "keyword" /o:+3:+3 /b:".{4}(.{8})" /$:1  "content1"  "content2"  c:\> rem quotes standard when "/$:1" switch used, eliminate they:  c:\> /f %a in ('^< input.txt findrepl "keyword" /o:+3:+3 /b:".{4}(.{8})" /$:1') @echo %~a content1 content2 

you may achieve large set of different find , find&replace operations using findrepl.bat program; may download this site.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -