Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux paste command

Linux paste command

Linux Command Reference Linux Command Reference

The Linux paste command is used to merge columns of files.

The paste command merges each file column by column, one column at a time.

Syntax

paste [-s][-d <间隔字符>][--help][--version][文件...]

Parameters:

Example

Use the paste command to merge the files "file", "testfile", and "testfile1" by entering the following command:



paste file testfile testfile1 #合并指定文件的内容 

However, before running the above command, first use the "cat" command to view the contents of the 3 files, as shown below:



$ cat file                  #file文件的内容  

xiongdan 200  

lihaihui 233  

lymlrl 231  

$ cat testfile              #testfile文件的内容  

liangyuanm  ss  

$ cat testfile1             #testfile1文件的内容  

huanggai 56  

zhixi 73 

After the merge command "$ paste file testfile testfile1" is executed, the terminal will display the merged file contents, as shown below:



xiongdan 200  

lihaihui 233  

lymlrl 231  

liangyuanm  ss  

huanggai 56  

zhixi 73  

Using the "-s" option of paste, you can merge multiple lines of a file into a single line for display. For example, to merge 3 lines of the file "file" into one line, enter the following command

$ paste -s file             #合并指定文件的多行数据

After the above command runs, the displayed data is as follows:



xiongdan 200 lihaihui 233 lymlrl 231 

Note: The "-s" option only changes how the testfile contents are displayed; it does not change the original file's format.

Linux Command Reference Linux Command Reference