Last updated on December 5th, 2022 at 06:50 pm

Here is a simple example of combining output of two files in to a file named, for example “new.txt” in Linux / Unix.

Assuming that we have 2 files named file1.txt & file2.txt

Table of Contents

Solution 1 , File Empty

If the file new.txt is an empty file, you can simply use the cat command :

cat file1.txt file2.txt > new.txt

Solution 2 , File Not Empty

If new.txt is not empty, and you want to keep its content as it is, and just want to append the concatenated output of two files into it then use this:

cat file1.txt file2.txt >> new.txt

Solution 3 , Multiple files

If you want to append two or more files to an existing file without overwriting the file ( for example file4.txt) content, then below is an example:

cat file1.txt file2.txt file3.txt >> file4.txt

Note: Even if the file file4.txt is not present, it would get created. If it is present, the other files’ contents will get appended to file4.txt

Leave a Reply

Your email address will not be published. Required fields are marked *