linux命令之paste

1.paste介绍

linux命令paste命令是把每个文件以列对列的方式,一列列地加以合并

2.paste用法

paste [参数] filename...

paste参数

参数

说明

-d

使用指定的分隔符进行合并

-s

以行来指定文件

3.实例

3.1.使用冒号(:)合并文件

命令:

paste -d : ztj-1.txt ztj-2.txt

[root@rhel77 ztj.bak]# cat ztj-1.txt 
1
3
5
7
9
[root@rhel77 ztj.bak]# cat ztj-2.txt 
2
4
6
8
10
[root@rhel77 ztj.bak]# paste -d : ztj-1.txt ztj-2.txt
1:2
3:4
5:6
7:8
9:10
[root@rhel77 ztj.bak]#

3.2.将文件中的多行数据合并为一行进行显示

命令:

paste -s ztj-1.txt

[root@rhel77 ztj.bak]# cat ztj-1.txt 
1
3
5
7
9
[root@rhel77 ztj.bak]# paste -s ztj-1.txt 
1	3	5	7	9(仅调整输出方式,并不会改变源文件的格式)
[root@rhel77 ztj.bak]#

3.3.以行来指定文件

命令:

paste -sd "=\n" ztj-1.txt

[root@rhel77 ztj.bak]# paste -sd "=\n" ztj-1.txt
1=3
5=7
9
[root@rhel77 ztj.bak]#

3.4.显示命令帮助信息

命令:

paste --help

[root@rhel77 ztj.bak]# paste --help
Usage: paste [OPTION]... [FILE]...
Write lines consisting of the sequentially corresponding lines from
each FILE, separated by TABs, to standard output.
With no FILE, or when FILE is -, read standard input.

Mandatory arguments to long options are mandatory for short options too.
  -d, --delimiters=LIST   reuse characters from LIST instead of TABs
  -s, --serial            paste one file at a time instead of in parallel
      --help     display this help and exit
      --version  output version information and exit

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'paste invocation'
[root@rhel77 ztj.bak]#

3.5.显示命令版本信息

命令:

paste --version

[root@rhel77 ztj.bak]# paste --version
paste (GNU coreutils) 8.22
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by David M. Ihnat and David MacKenzie.
[root@rhel77 ztj.bak]#