Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I create a new file "new.txt" that is a concatenation of "file1.txt" and "file2.txt" in Unix?

share|improve this question

migrated from Jan 4 '11 at 9:28

This question came from our site for professional and enthusiast programmers.

zcat file1.txt.gz > new.txt for gzip files – frops Dec 18 '15 at 14:47
cat file1.txt file2.txt > new.txt
share|improve this answer
cat actually means concatenate. – grawity Jan 4 '11 at 13:44
I don't even know how to use Linux and I knew this. Sounds like a homework question to me :) – Shinrai Jan 4 '11 at 21:11
Helpful addition: With a ">" the target-file is overwritten with the source-files and with ">>" the source-files are appended to the target-file – agporwfnz29 Jan 4 '11 at 23:14
Bash, ksh, zsh: cat file{1,2}.txt > new.txt – Dennis Williamson Jan 4 '11 at 23:30

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

cat file1.txt file2.txt > new.txt

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
share|improve this answer

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

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

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

share|improve this answer

You must log in to answer this question.