1.

Solve : Insert the content of a text file to another text file after the pattern(batch)?

Answer»

Hi everyone!
My goal is to insert the content of a text file into another text file.
Let's say the input.txt looks like this:

Code: [Select]
<Next half add call="Questions"&GT;
<random text="A_DATA">filename.txt</random>
<random text="A_DATUM">1</random>
<random text="B_DATA">filename2.txt</random>
<random text="B_DATUM">1</random>
<random text="OFF_set">0</random>
<random text="LINE_set">0</random>
<random text="OFF_step">1</random>
<random text="LINE_step">1</random>
</Next half>

And the output.txt looks like this:

Code: [Select]<Random textXSize="0001" textYSize="002">
<Announcing of invitation principles="randomtext" number="1">
<Simple>
<Filename relative="0">###################################</Filename>
<Source>1</Source>
<Properties textXSize="0001" textYSize="002" Type="You" wordXSize="033" wordYSize="19" />
</Simple>
</Band>
</Set>


How will I insert everything from the input.txt to the output.txt after this line <Random textXSize="0001" textYSize="002">? And save the file as output.txt?

TIAThere is a chance that the text is XML files with no line breaks, and that would change the solution.

What kind of line endings are in the files?

Sorry. But what do you mean by line endings?Windows has a carriage return/linefeed pair at the end of each line.
Unix/Linux and Mac uses different systems.

XML files can be on a single line, but the editor and viewer makes them appear to be on multiple lines.

Your file is probably a Windows generated one, but the question of it being on a single line will change the solution.Instead of using this I have posted another question maybe you could check it. Thanks! It would help enormously to give you a solution, and reduce pointless threads, if you answer questions - and explain the situation properly.Quote from: _unknown_ on January 25, 2016, 08:11:56 PM

Instead of using this I have posted another question maybe you could check it. Thanks!
Foxidrive's question is still valid on your new question. You should not have started another topic.Quote from: Squashman on January 28, 2016, 11:50:06 AM
Foxidrive's question is still valid on your new question. You should not have started another topic.


Sorry i thought it was different.Perhaps this is the end of this thread.
Here is what I wanted to say.
DOS batch can be used for search and insert in a text file. But it is not the best choice. Others tools work better and are easy to use.

Is this for use by just one administrator?
Is this SOMETHING that would be done on a daily basis?
A batch file is sometimes needed for a number of users who do not have other tools available. Is that the case here?

Batch can be used with other tools Such as VBScript and Powershell.
Also, some programmers even import tools used in Unix or Linux.

Such as sed and grep.

from CH search:
About grep
grep, which stands for "global regular expression print," processes text line by line and prints any lines which match a specified pattern.
About sed
sed, short for "stream editor", allows you to filter and TRANSFORM text

Also SEE:
http://stackoverflow.com/questions/1169927/using-sed-and-grep-to-search-and-replace

There are VERSIONS of sed and grep[ that work in the windows command line.
Just trying to help.


Discussion

No Comment Found