Полезная информация

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 35.17 Making Text in Columns with pr Chapter 35
You Can't Quite Call This Editing
Next: 35.19 Joining Lines with join

35.18 Pasting Things in Columns

Do you ever wish you could paste two (or even three) files side by side? You can, if you have the System V paste program (or the public-domain implementation on the disc).

For example, to create a three-column file from files x, y, and z:

$ paste x y z > file

To make paste read standard input, use the - option, and repeat - for every column you want. For example, to make an old broken System V ls (which lists files in a single column) list files in four columns:

$ ls | paste - - - -

The "standard input" option is also handy when used with cut (35.14). You can cut data from one position on a line and paste it back on another.

The separate data streams being merged are separated by default with a tab, but you can change this with the -d option. Unlike the -d option to cut, you need not specify a single character; instead, you can specify a list of characters, which will be used in a circular fashion. (I haven't figured a use for this - maybe you can.)

The characters in the list can be any regular character or the following escape sequences:








empty string

Use quoting (8.14), if necessary, to protect characters from the shell.

There's also a -s option that lets you merge subsequent lines from one file. For example, to merge each pair of lines onto a single line:

$ paste -s -d"\t\n" list


Previous: 35.17 Making Text in Columns with pr UNIX Power ToolsNext: 35.19 Joining Lines with join
35.17 Making Text in Columns with pr Book Index35.19 Joining Lines with join

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System