Concatenating Text

The cat tool gets its name because it concatenates all of the text given to it, outputting the result to the standard output. It is useful for concatenating files of text together. For example, suppose you have two files, `early' and `later'. The file `early' contains this text:

This Side of Paradise
The Beautiful and Damned

And the file `later' contains this text:

The Great Gatsby
Tender Is the Night
The Last Tycoon

To concatenate these files into a new file, `novels', type:

$ cat early later 62; novels RET

This command redirects the standard output to a new file, `novels', which would then contain the following text:

This Side of Paradise
The Beautiful and Damned
The Great Gatsby
Tender Is the Night
The Last Tycoon

The files `early' and `later' are not altered. Had you typed cat later early > novels instead, the files would be concatenated in that reversed order instead, beginning with `later'; so the file `novels' would contain the following:

The Great Gatsby
Tender Is the Night
The Last Tycoon
This Side of Paradise
The Beautiful and Damned

The following sections give other recipes for concatenating text.

NOTE: You can also use cat to concatenate files that are not text, but its most popular usage is with text files. Another way to concatenate files of text in an automated way is to use file inclusion−−−see Including Text Files. A similar tool, zcat, reads the contents of compressed files.

Posted on: 16/12/2009








0 Comments
If you want to leave a comment please Login or Register
How to backup your data using rsync......
Understanding autoconf......
The Basics of fdisk......
Accessing Memory Using DMA......
The fd Directory......