• Combine text files (XP/UltraEdit)

    Author
    Topic
    #417233

    Every day my customer has a dozen text files (*.txt) that he needs to combine into one text file. Is there a way to combine them without having to copy and paste the text out of each one? File names are variable (and unpredictable). He’s using a product called UltraEdit, but I’m open to ideas. Thanks!

    Viewing 1 reply thread
    Author
    Replies
    • #935513

      Hi Sarah,

      What you’re looking for is something like the Unix “cat” command, which concatenates any number of files into a single one.

      I’d suggest one of two options (there are certainly many more).

      First, that’s a one-liner in Perl. Perl is available for free from http://www.activestate.com. With Perl installed, you could do this at the DOS command line:

      > perl -ne "print" file1.txt file2.txt file3.txt > bigfile.txt
      

      If you’re not interested in that approach, there are a few folks out there who have ported common Unix commands, like cat, to Windows. Check out: http://www.kilowattsoftware.com/PoofPage.htm%5B/url%5D. With cat installed, you could do this at the DOS command line:

      > cat file1.txt file2.txt file3.txt > bigfile.txt
      

      If it were my decision, I’d create a Perl script (just a text file) named “cat.pl”, consisting of the following:

      while () {print};
      

      And save that in C:Windows, so it’s always available, right from the command line, like this:

      > cat file1.txt file2.txt file3.txt > bigfile.txt
      

      In fact, I just did that, since it actually would be nice to have cat on my Windows machine.

      Cheers!

      • #935519

        Thanks, Andrew. That should work. He could probably use the VBA that comes with Office rather than installing something new, but the principle is the same.

    • #935576

      you’ve posted this in the Word forum I’m assuming that the end target is a Word file (albeit in text format)? In which case a wee VBA routine to create a new empty document followed by a loop to insert each of the .txt files from a chosen directory. Something along the lines of

      Documents.Add
      ChDir “C:txtfiles”
      txtName = Dir(“*.txt”)
      While txtName “”
      With Selection
      .InsertFile FileName:=txtName, ConfirmConversions:=False
      .InsertParagraphAfter
      .Collapse Direction:=wdCollapseEnd
      End With
      txtName = Dir()
      Wend

      At the end of this the Word doc contains the contents of the .txt files in the order that the Dir function serves them up – which raises the question of whether they need to be combined in a particular order?

      If it is inconvenient to use a fixed directory name then you can always use the FileDialog object to allow navigating to a directory of choice and then selection of the .txt files to deal with – if order was a problem then presumably the dialog could be called repeatedly to choose one file at a time (slow but probably the only way to deal with unpredictable file names if there is a particular order of concatenation required)

    Viewing 1 reply thread
    Reply To: Combine text files (XP/UltraEdit)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: