Search and then replace whole lines with variables in a txt file using a script package

I am trying to create a .bat file that will replace a set of variables (in order) with the entire line of text.

I used to pull an array of three lines of text from the file "variables.txt":

@echo off setlocal ENABLEDELAYEDEXPANSION set vidx=0 for /F "tokens=*" %%A in (variables.txt) do ( SET /A vidx=!vidx! + 1 set var!vidx!=%%A ) set var 

I want to scan the file "export.txt", and the first time I access the word "client" I want to replace all this line with the first variable.

The second time, when he clicks on the word "client", I want him to replace the entire line of the second variable (and so on).

It's really hard for me, and I'm not sure about the plural variable in the for / F sequence.

+4
source share
1 answer

You are almost there, you just need to iterate over the lines containing client

 set vidx=0 for /F "tokens=*" %%A in ('findstr "client" export.txt') do ( SET /A vidx=!vidx! + 1 set var!vidx!=%%A ) set var 

for the file export.txt:

 blah client test1 test1 blah blah blah client test2 test 2 blah blah blah test client test3 

:

 var1=client test1 test1 var2=client test2 test 2 var3=test client test3 
+1
source

Source: https://habr.com/ru/post/1438994/


All Articles