Combining Files

Several commands that can combine file contents for various purposes will be covered in this section. The files can be combined and intertwined in sorted order. They can be concatenated one after the other. They can be pasted side by side on each line or joined side by side where a line in one file is paired with the corresponding line in a second file. These combinations do not affect the original files. The results can be redirected and saved in another file, if desired.

Sorting Multiple Files Together

You looked at sort at the beginning of this chapter. If sort is called with a list of files on the command line, sort first merges their contents and then displays the combined contents in sorted order, as shown here:

sort file1 ...

Get Practical UNIX now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.