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

Author Topic: need help: How to write a batch to combine more 100 text files to one text file?  (Read 16643 times)

0 Members and 1 Guest are viewing this topic.

ghostdog74



    Specialist

    Thanked: 27
    what happened?? did i miss anything??

    Salmon Trout

    • Guest
    what happened?? did i miss anything??

    bill said hi to some chick called Liz. Twice.

    billrich



      Rookie

      Thanked: 1
      Code: [Select]
      c:\test> cat *.txt > newfile.txt

      We all have gone around the barn instead of directly through the barn.

      The following one line by Casper is the solution:

      cat *.txt > newfile.txt

      or the batch equivilant :

      type *.txt > newfile.txt

      p.s.  Try it; it works.

      Geek-9pm


        Mastermind
      • Geek After Dark
      • Thanked: 1026
        • Gekk9pm bnlog
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      Quote
      I knew I can do it by copy command like: file1.txt+file2.txt.... file all.txt. however it is not efficient way.

      OK. Glad to see you got a cool answer.Neat
      Now I have a question.
      In what way is the more efficient?
       

      billrich



        Rookie

        Thanked: 1
        OK. Glad to see you got a cool answer.Neat
        Now I have a question.
        In what way is the more efficient?
         

        I agree copy, cat   and  type are all efficient. 

        More than one way to skin a cat.


        Helpmeh



          Guru

        • Roar.
        • Thanked: 123
          • Yes
          • Yes
        • Computer: Specs
        • Experience: Familiar
        • OS: Windows 8
        We all have gone around the barn instead of directly through the barn.

        The following one line by Casper is the solution:

        cat *.txt > newfile.txt

        or the batch equivilant :

        type *.txt > newfile.txt

        p.s.  Try it; it works.
        But there could be other .txt files in the folder.
        Where's MagicSpeed?
        Quote from: 'matt'
        He's playing a game called IRL. Great graphics, *censored* gameplay.

        Salmon Trout

        • Guest
        billrich totally missed the point once again.

        billrich



          Rookie

          Thanked: 1
          But there could be other .txt files in the folder.

          dir /s  *.txt or type *.txt or cat *.txt finds all the text (.txt ) files in the folder.

          Test the above commands in any folder with text (.txt ) files.

          _______________________________________ ________

          The following code found nothing and/or many duplicates:

          @echo off
          for /l %%a in (0,1,ENDNUMBER) do type file%%a.txt >> endresult.txt

          The Casper code works:

          cat *.txt > newfile.txt

          -------------------------------------
          Dias de verano  who now calls her/himself Salmon Trout is confused and lost as usual.

          Geek-9pm


            Mastermind
          • Geek After Dark
          • Thanked: 1026
            • Gekk9pm bnlog
          • Certifications: List
          • Computer: Specs
          • Experience: Expert
          • OS: Windows 10
          Quote
          The Casper code works:
          cat *.txt > newfile.txt
          OK. That is True.
          What I do not understand is why he ended to put all hte TXT files into one. Any pratical application can get to all the files anyway.
          What real application is the out there that has to have all hte TXT files in a directory merged into just one?

          I think the right answer is You don't have too!

          It is like asking an Eagle if he ...
          knows how to hike in to Tuolumne Meadows in Yosemite.


          He would say "I don't have too!"


          Helpmeh



            Guru

          • Roar.
          • Thanked: 123
            • Yes
            • Yes
          • Computer: Specs
          • Experience: Familiar
          • OS: Windows 8
          Good point geek. And bill, the op already said that the problem was solved, so I don't understand why there are other solutions that don't function as properly poster after the fact.
          Where's MagicSpeed?
          Quote from: 'matt'
          He's playing a game called IRL. Great graphics, *censored* gameplay.

          ghostdog74



            Specialist

            Thanked: 27
            We all have gone around the barn instead of directly through the barn.

            The following one line by Casper is the solution:

            cat *.txt > newfile.txt

            or the batch equivilant :

            type *.txt > newfile.txt

            p.s.  Try it; it works.

            no, they are not equivalent. You should try it yourself and see. type will give you the file name as well.

            ghostdog74



              Specialist

              Thanked: 27
              OK. Glad to see you got a cool answer.Neat
              Now I have a question.
              In what way is the more efficient?
               
              i think he meant that if he has 100 text files, he is not going to type file1+file2+.....file100 on the command line like that. the more convenient way, which i think he missed out,
              Code: [Select]
              c:\test> copy file*txt output.txt

              billrich



                Rookie

                Thanked: 1
                And bill, the op already said that the problem was solved, so I don't understand why there are other solutions that don't function as properly poster after the fact.

                The following code does not work:

                @echo off
                for /l %%a in (0,1,ENDNUMBER) do type file%%a.txt >> endresult.txt

                ------------------------------------------------

                Casper did nothing wrong by offering  a simple one line solution.  The readers of this board  enjoy more than one solution.

                Please thank Casper for his insight:

                The Casper code works:
                cat *.txt > newfile.txt

                ______________________________
                Geek,

                I have no idea what Netsking, the original poster, intentions are.  

                Why does  Netsking, OP, need all the text files in a folder in one large file?

                Perhaps for his Boss?

                Thanks Ceek for your insight.   A few people understood the problem and the solutions.  It was really quite a simple problem.  Casper showed us the simple solution.

                Thanks Casper.

                ghostdog74



                  Specialist

                  Thanked: 27
                  OK. That is True.
                  What I do not understand is why he ended to put all hte TXT files into one. Any pratical application can get to all the files anyway.
                  well, if you have not encountered this scenario, it doesn't mean other's won't. Say for example, you have many text log files which you generate each day and its cluttering up your screen when you do dir listings. And they are many years old. Then you might want to concat them according to each month and each year to get rid of these pieces to reduce the amount of files you have. this is just an example, but there certainly are uses for concatenation of files.


                  Helpmeh



                    Guru

                  • Roar.
                  • Thanked: 123
                    • Yes
                    • Yes
                  • Computer: Specs
                  • Experience: Familiar
                  • OS: Windows 8
                  Hey bill, try reading next time.
                  I got it. I rewrite it  as you mentioned. This time it works. Thank you very much for your help.


                  Where's MagicSpeed?
                  Quote from: 'matt'
                  He's playing a game called IRL. Great graphics, *censored* gameplay.