Insert txt file after string in another file

February 28, 2011 at 13:38:21
Specs: Windows 7
I am trying to create an automated installer for my company's software. I am stuck at a point where I have to insert a string of text that is stored in one txt file into another. However, I need it to be inserted after a certain string in the second file. This file will be the same at all times.

If you can help that would be great

See More: Insert txt file after string in another file

Report •

February 28, 2011 at 14:05:13
I assume you got the string from the first file and stored it into a variable (e.g. string).

@echo off & setlocal EnableDelayedExpansion
type nul >
for /F "delims=" %%j in (file2.txt) do (
  set line=%%j
  if not "!line!"=="!line:TARGET STRING=!" set line=!line:TARGET STRING=TARGET STRING%string%!
del file2.txt
ren file2.txt

Where the environment variable string holds the text to be inserted and TARGET STRING is the string you have to insert the text after.

Report •

March 1, 2011 at 04:24:23
I don't have the string from the first file stored, and I'm not sure how I would go about doing that.

Something along the lines of %1 = file1.txt?

Report •

March 1, 2011 at 05:13:41
You must explain the structure of the first file, i.e. how is the string located inside?

Report •

Related Solutions

March 2, 2011 at 08:50:31
The string is an XML structure about 10 lines long

Report •

March 2, 2011 at 09:04:05
Is it the full content of File1.txt or located somewhere inside File1.txt?

Please, be the most exaustive possible when explaining your issues.

Be aware a variable can not store more than ONE line of text since it is ended by CR/LF. More you can't just insert a structure after a string into File2.txt if that contains CR/LF.

Your problem sounds now more confused.

Report •

March 2, 2011 at 10:30:42
I ended up finding a solution here...

I appreciate your help, but this did exactly what I was looking for.

Report •

Ask Question