R
R
Rinat Norezov2019-10-22 20:14:14
cmd/bat
Rinat Norezov, 2019-10-22 20:14:14

How to copy lines after and before certain words?

There is a text file list_all.txt with approximately the following content:

Список хим. товаров:
Крем
Шампунь
Мыло
Лак для волос
Крем
....
еще много строк
....

Список прод. товаров:
....
....

It is necessary to copy all the lines after "Chemicals list:" and before "Products list:" into the file list_him.txt, without the phrases "Chemicals list:" , "Products list:".
To make list_him.txt look like this:
Крем
Шампунь
Мыло
Лак для волос
Крем
....
еще много строк
....

I found something similar on this BAT site. How to copy a part of a file starting from a certain line? :
@echo off
set "file=list_all.txt"
set "search=Список хим. товаров"
set "header_line="
for /f "tokens=1  delims=[]" %%a in ('find /i /n "%search%" "%file%" ') do set "header_line=%%a"
if defined header_line (
  more +%header_line% "%file%"
) >>list_him.txt
pause

But it copies everything after the desired phrase, how can I make it copy only after, and only before?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question