How to append contents of multiple files into one file

Steam picture Steam · Aug 2, 2013 · Viewed 364.4k times · Source

I want to copy the contents of five files to one file as is. I tried doing it using cp for each file. But that overwrites the contents copied from the previous file. I also tried

paste -d "\n" 1.txt 0.txt

and it did not work.

I want my script to add the newline at the end of each text file.

eg. Files 1.txt, 2.txt, 3.txt. Put contents of 1,2,3 in 0.txt

How do I do it ?

Answer

radical7 picture radical7 · Aug 2, 2013

You need the cat (short for concatenate) command, with shell redirection (>) into your output file

cat 1.txt 2.txt 3.txt > 0.txt