Command Line Basics: Join Files With cat

October 19, 2009 by
Filed under: command line, HowTo, linux 

I've already shown you how to view files with the cat command. In today's post I'm going to show you how to use the GNU cat command for its originally intended purpose: for joining multiple files together.

For this example we'll need a couple of text files to start with. Paste the following text into a text editor and save it as file1.

item 1
item 2
item 3

Repeat the process with the following text and save it as file2.

item 4
item 5
item 6

You can verify the contents of your files by viewing them with cat.

Affiliate Link
cat file1
cat file2

Now you can use cat to join the contents of the two files and display it on the terminal.

cat file1 file2

To create a new file with the combined contents of the first two you simply use output redirection.

cat file1 file2 >file3

Now you can use cat again to view the contents of file3.

cat file3

You should see

item 1
item 2
item 3
item 4
item 5
item 6

Comments

One Response to “Command Line Basics: Join Files With cat”

  1. Story added...

    This story has been submitted to fsdaily.com! If you think this story should be read by the free software community, come vote it up and discuss it here:

    http://www.fsdaily.com/Beginner/Command_Line_Basics_Join_Files_With_cat/

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>