How to Combine or Merge Multiple Text Files into one in Ruby

How to Combine or Merge Multiple Text Files into one in Ruby

You can combine two or more TXT documents into a single text file programmatically on the cloud using REST API. Text file merging is commonly used where files are changed by different users or systems. Text merging combines all text changes into a single file to avoid overlapping of data. As a Ruby developer, you can merge or combine multiple text(.txt) files into a single file in your Ruby applications. In this article, you will learn how to combine or merge multiple Text files into one in Ruby.

The following topics shall be covered in this article:

Text File Merger REST API - Installation

To combine multiple text files, we will be using the Ruby SDK of GroupDocs.Merger Cloud API. It allows you to combine two or more documents into a single document, or split up into multiple documents. It also enables you to move, delete, exchange, rotate or change the page orientation either as portrait or landscape for the whole or specific range of pages. Ruby SDK supports merging and splitting of all popular document formats such as Word, Excel, PowerPoint, Visio, OneNote, PDF, HTML, etc.

You can install GroupDocs.Merger Cloud to your Ruby application using the following command in the console:

gem install groupdocs_merger_cloud

Please get your Client ID and Secret from the dashboard before following the mentioned steps. Once you have your ID and secret, add in the code as shown below:

Combine or Merge Multiple Text Files using REST API in Ruby

You can merge or combine two or more text files programmatically on the cloud by following the simple steps mentioned below:

  • Create an instance of the DocumentApi
  • Create an instance of the JoinItem
  • Set the input file path for first JoinItem in the FileInfo
  • Create new instance of the JoinItem for the second document
  • Provide the input file path for second JoinItem in the FileInfo
  • Add more JoinItems to merge more Text files
  • Create an instance of the JoinOptions
  • Add a comma separated list of created join items
  • Set the output file path on the cloud
  • Create an instance of the JoinRequest with JoinOptions
  • Get results by calling the join() method of the DocumentAPI with JoinRequest

This is the secure and fastest way to combine two or more text documents into a single file programmatically. The following code snippet shows how to merge multiple text files using REST API in Ruby:

Merge Specific Pages of Two or More Text Files using Ruby

You can also combine specific pages of multiple text files into a single file programmatically by following the steps mentioned below:

  • Create an instance of the DocumentApi
  • Create an instance of the JoinItem
  • Set the input file path for first JoinItem in the FileInfo
  • Provide the list of page numbers to be merged in array
  • Create another instance of the JoinItem
  • Set the input file path for second JoinItem in the FileInfo
  • Now provide the start page and end page number
  • Set the page range mode as OddPages
  • Next, Create an instance of the JoinOptions
  • Add a comma separated list of joined items
  • Set the output file path on the cloud storage
  • Create an instance of the JoinRequest with JoinOptions
  • Finally, merge documents by calling the join() method of the DocumentAPI with JoinRequest

The following code snippet demonstrate how to merge specific pages from multiple text files using REST API in Ruby:

Online Text File Merger for Free

How to merge multiple text files into one? Please try the following free online text file merger tool, which is developed using the above API. You can combine text files online from any device using our TXT merger API.

Summing up

In this blog post, we have learned,

  • how to combine and merge multiple text files on the cloud;
  • how to combine specific pages of multiple text documents into one file;

Text merger REST API also provides .NET, Java, PHP, Python, Android, and Node.js SDKs as its document merger family members for the Cloud API. You can learn more about GroupDocs.Merge Cloud API using the documentation. We also provide an API Reference section that lets you visualize and interact with our APIs directly through the browser.

Ask a question

If you have any questions about how to combine multiple text files, please feel free to ask in Free Support Forum and it will be answered within a few hours.

See Also