Find out how to Concatenate Recordsdata in Linux

With the ability to mix varied information collectively into one might be very useful. You possibly can prepare and kind out your desktop and mix a number of associated paperwork into one. In Linux, there are a number of methods to concatenate information collectively. This tutorial exhibits all of the methods to do it: they’re all fairly easy, actually.
Concatenating Recordsdata by way of the Command Line
The command line is the simplest option to concatenate information in Linux. All you want is the Linux terminal or a good terminal emulator.
There are just a few terminal instructions that will let you concatenate information in Linux:
The most well-liked amongst them is the cat
command. You possibly can mix a number of information collectively into one through the use of the next format:
cat "file1.txt" "file2.txt" >> "file3.txt"
It may be carried out with different instructions as properly:
be a part of file1.txt file2.txt > file3.txt

Notice: your Linux system might ask for superuser privileges to make use of the be a part of
command. Add sudo
earlier than coming into the be a part of
command to permit that.
paste -d "" file1.txt file2.txt > file3.txt

sed -e "r file2.txt" file1.txt > file3.txt

Concatenating Folders of Recordsdata
In case you have a ton of information to concatenate, you’ll be able to retailer them in folders and concatenate the contents of every folder right into a single file. The one exception is the be a part of
command, which doesn’t will let you do this.
These instructions will will let you concatenate folders of information:
cat dog_folder/* > output_file.txt

paste -d '' dog_folder/* > output_file.txt

sed -s '' dog_folder/* > output_file.txt

These will concatenate all of the information inside the “dog_folder” into one file named “output_file.txt”. Do observe that the order of concatenation when doing it with information grouped into folders relies on the file names: numerical first, then alphabetical.
Different Methods to Concatenate Recordsdata in Linux
Concatenation instructions are nice, however there are different ways in which will let you do it a lot sooner – particularly with video, audio, and PDF information. Not like concatenation instructions, nonetheless, these might be fairly choosy with the file kind you’re utilizing with them.
Utilizing a Concatenation Program
Whereas it gained’t work with textual content information, FFmpeg will mix audio and video information. As a bonus, it could possibly additionally convert information to your required format.
Use PDFtk to concatenate PDF information collectively. See the next instance:
pdftk file1.pdf file2.pdf cat output file3.pdf

Utilizing a Net App
One other option to concatenate information on Linux is thru an online app. Whereas they inherently possess a safety flaw (a spoofer can steal your knowledge whilst you ship it to the online app, for instance), that flaw usually gained’t be an enormous deal for most individuals who simply wish to mix pages 1 and a couple of of their resumes.
One instance is PDF Joiner. This internet app means that you can drag as much as 20 information into the white field and hit “Be a part of Recordsdata” to concatenate them into one.

Some Limits of Concatenation
Whereas extremely helpful, concatenation can result in some complicated digital jargon, particularly if you concatenate information of a unique format collectively.
For instance: suppose you had two information: “strings.txt” and “picture.png.” In the event you mixed them collectively, you might get one thing that regarded like a corrupt file.

The rule of thumb is to solely concatenate information of the identical file kind, and use an utility that may deal with that file kind.
Often Requested Questions
How do I add a file with an area in its identify on a Linux command line?
For Linux, you’ll be able to write information with areas by placing them in between citation marks within the command line.
Why do I get a newline between characters once I concatenate textual content information?
Most textual content information finish with a factor we name a “newline character.” For computer systems, this can be a particular character that claims, “you’ve reached the tip,” which indicators text-editing packages to cease parsing textual content, as there’s no extra on the finish.