GroupDocs.Merger for Python via .NET makes it easy to combine multiple plain-text files into a single TXT file programmatically. No third-party software or text editor is required.
A file with the .TXT extension represents a text document that contains plain text organized in lines. Paragraphs are recognized by carriage returns, and the content is human-readable as a sequence of characters. Standard text documents can be opened in any text editor or word processing application on any operating system.
Steps to merge TXT files
Create an instance of the Merger class and pass the path to the first (base) TXT file.
Call merger.join() with the path to each additional TXT file to append.
Call merger.save() with the desired output path to write the merged file.
fromgroupdocs.mergerimportMergerdefmerge_text_documents():# Load the first text file as the merge basewithMerger("./input.txt")asmerger:# Append the second text filemerger.join("./input2.txt")# Save the combined text filemerger.save("./output.txt")if__name__=="__main__":merge_text_documents()
input.txt is a sample file used in this example. Click here to download it.
input2.txt is a sample file used in this example. Click here to download it.
EXAMPLE 1 EXAMPLE 1 EXAMPLE 1
EXAMPLE 2 EXAMPLE 2 EXAMPLE 2
EXAMPLE 3 EXAMPLE 3 EXAMPLE 3
EXAMPLE 4 EXAMPLE 4 EXAMPLE 4
EXAMPLE 5 EXAMPLE 5 EXAMPLE 5
EXAMPLE 6 EXAMPLE 6 EXAMPLE 6
EXAMPLE 1 EXAMPLE 1 EXAMPLE 1
EXAMPLE 2 EXAMPLE 2 EXAMPLE 2
EXAMPLE 3 EXAMPLE 3 EXAMPLE 3
EXAMPLE 4 EXAMPLE 4 EXAMPLE 4
[TRUNCATED]