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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.