Results 1 to 5 of 5
  1. #1
    Star Lounger
    Join Date
    Apr 2002
    Location
    Pleasant Hill, CA
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Combine text files (XP/UltraEdit)

    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!

  2. #2
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Combine text files (XP/UltraEdit)

    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 www.activestate.com. With Perl installed, you could do this at the DOS command line:
    <pre>> perl -ne "print" file1.txt file2.txt file3.txt > bigfile.txt
    </pre>


    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. With cat installed, you could do this at the DOS command line:
    <pre>> cat file1.txt file2.txt file3.txt > bigfile.txt
    </pre>

    If it were my decision, I'd create a Perl script (just a text file) named "cat.pl", consisting of the following:
    <pre>while (<>) {print};
    </pre>

    And save that in C:Windows, so it's always available, right from the command line, like this:
    <pre>> cat file1.txt file2.txt file3.txt > bigfile.txt
    </pre>

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

    Cheers!

  3. #3
    Star Lounger
    Join Date
    Apr 2002
    Location
    Pleasant Hill, CA
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Combine text files (XP/UltraEdit)

    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.

  4. #4
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Combine text files (XP/UltraEdit)

    Apparently you can also use the built-in DOS copy command:
    <pre>> copy file1.txt file2.txt bigfile.txt
    </pre>

    The name of the destination file comes last. See http://www.computerhope.com/copyhlp.htm#03.

    It would be fairly simple to write a VBA macro to do this using the Shell command.

  5. #5
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Combine text files (XP/UltraEdit)

    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)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •