Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Insert the content of a text file to another text file after the pattern(batch)  (Read 4777 times)

0 Members and 1 Guest are viewing this topic.

_unknown_

    Topic Starter


    Beginner

    • Experience: Beginner
    • OS: Windows 7
    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"> 
         <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?

    TIA

    foxidrive



      Specialist
    • Thanked: 268
    • Experience: Experienced
    • OS: Windows 8
    There 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?


    _unknown_

      Topic Starter


      Beginner

      • Experience: Beginner
      • OS: Windows 7
      Sorry. But what do you mean by line endings?

      foxidrive



        Specialist
      • Thanked: 268
      • Experience: Experienced
      • OS: Windows 8
      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.

      _unknown_

        Topic Starter


        Beginner

        • Experience: Beginner
        • OS: Windows 7
        Instead of using this I have posted another question maybe you could check it. Thanks!

        foxidrive



          Specialist
        • Thanked: 268
        • Experience: Experienced
        • OS: Windows 8
        It would help enormously to give you a solution, and reduce pointless threads, if you answer questions - and explain the situation properly.

        Squashman



          Specialist
        • Thanked: 134
        • Experience: Experienced
        • OS: Other
        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.

        _unknown_

          Topic Starter


          Beginner

          • Experience: Beginner
          • OS: Windows 7
          Foxidrive's question is still valid on your new question.  You should not have started another topic.


          Sorry i thought it was different.

          Geek-9pm


            Mastermind
          • Geek After Dark
          • Thanked: 1026
            • Gekk9pm bnlog
          • Certifications: List
          • Computer: Specs
          • Experience: Expert
          • OS: Windows 10
          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.  ;)