Linux paste命令用法汇总

吾爱主题 阅读:123 2024-04-05 15:07:02 评论:0

一、paste命令使用方法

1.1 paste命令作用

paste命令用于合并文件行

1.2 paste命令选项

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

二、paste命令使用实例

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

?
1 2 3 4 5 6 7 name domain ip area user password role

demo2.conf内容如下

?
1 2 3 4 5 6 7 test test 127.0.0.1 china admin admin admin

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

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

?
1 2 3 4 5 6 7 8 9 [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命令是不会改变源文件的,此时查看两个文件如下,可以发现内容确实没有改变。

?
1 2 3 4 5 6 7 8 9 10 [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] #

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

?
1 2 3 4 5 6 7 8 9 10 [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参数指定间隔符,如下所示指定使用等号间隔

?
1 2 3 4 5 6 7 8 9 10 [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形式的输出等场景下是非常有用的。

?
1 2 3 4 5 [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命令使用内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://blog.csdn.net/redrose2100/article/details/128372087

可以去百度分享获取分享代码输入这里。
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

【腾讯云】云服务器产品特惠热卖中
搜索
标签列表
    关注我们

    了解等多精彩内容