Content

Linux paste命令用法汇总(linux查看ipv6邻居)硬核推荐

文章摘要

文章介绍了Linux `paste` 命令的使用方法及其主要功能。`paste` 命令主要用于合并文件的行,并支持多种选项:`-d` 用于指定自定义间隔符,默认为 `tab`,`-s` 用于串行合并,将两个文件的内容按顺序拼接成两行。文章通过多个实例展示了如何使用 `paste` 命令按照行合并文件、指定间隔符以及串行合并文件。此外,还说明了如何将合并结果保存到文件中。文章强调了 `paste` 命令的高效性和灵活性,特别适用于需要高效数据处理的场景。


目录一、paste命令使用方法1.1 paste命令作用1.2 paste命令选项二、paste命令使用实例2.1 将两个文件,按照行合并2.2 将两个文件按照行合并,同时指定间隔符2.3 将两个文件串行合并

paste命令用于合并文件行

-d: 自定义间隔符,默认为tab-s:串行处理,非并行

首先准备两个文件demo1.conf和demo2.conf,其中demo1.conf内容如下:

name domain ip area user password role

demo2.conf内容如下

test test 127.0.0.1 china admin admin admin

如下,此时将两个文件按照行合并,同时中间默认使用tab间隔,同时将结果打印出来

[root@jiayi-centos-01 opt]# paste demo1.conf demo2.conf name test domain test ip 127.0.0.1 area china user admin password admin role admin [root@jiayi-centos-01 opt]#

需要注意的,paste命令是不会改变源文件的,此时查看两个文件如下,可以发现内容确实没有改变。

[root@jiayi-centos-01 opt]# paste demo1.conf demo2.conf > demo.conf [root@jiayi-centos-01 opt]# cat demo.conf name test domain test ip 127.0.0.1 area china user admin password admin role admin [root@jiayi-centos-01 opt]#

如果希望将合并结果保存起来则可以使用重定向符号,如下所示

[root@jiayi-centos-01 opt]# paste demo1.conf demo2.conf > demo.conf [root@jiayi-centos-01 opt]# cat demo.conf name test domain test ip 127.0.0.1 area china user admin password admin role admin [root@jiayi-centos-01 opt]#

通过-d参数指定间隔符,如下所示指定使用等号间隔

[root@jiayi-centos-01 opt]# paste -d=demo1.conf demo2.conf > demo.conf [root@jiayi-centos-01 opt]# cat demo.conf name=test domain=test ip=127.0.0.1 area=china user=admin password=admin role=admin [root@jiayi-centos-01 opt]#

所谓串行合并,就是把第一个文件的内容放在第一行,把第二个文件的内容放在第二行,通过-s 参数实现,如下所示,可以发现,这种在打印table形式的输出等场景下是非常有用的。

[root@jiayi-centos-01 opt]# paste -s demo1.conf demo2.conf > demo.conf [root@jiayi-centos-01 opt]# cat demo.conf name domain ip area user password role test test 127.0.0.1 china admin admin admin [root@jiayi-centos-01 opt]#

到此这篇关于Linux paste命令使用详解的文章就介绍到这了,更多相关Linux paste命令使用内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:Linux paste命令的使用方法