Linux----paste命令使用详解

【原文链接】Linux----paste命令使用详解

一、paste命令使用方法

1.1 paste命令作用

paste命令用于合并文件行

1.2 paste命令选项

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

二、paste命令使用实例

首先准备两个文件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

2.1 将两个文件,按照行合并

如下,此时将两个文件按照行合并,同时中间默认使用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]# cat demo1.conf
name
domain
ip
area
user
password
role
[root@jiayi-centos-01 opt]# cat demo2.conf
test
test
127.0.0.1
china
admin
admin
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]#

2.2 将两个文件按照行合并,同时指定间隔符

通过-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]#

2.3 将两个文件串行合并

所谓串行合并,就是把第一个文件的内容放在第一行,把第二个文件的内容放在第二行,通过-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]#
  • 1
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

redrose2100

您的鼓励是我最大的创作动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值