日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁 編程語言 正文

Linux?paste命令用法匯總_linux shell

作者:redrose2100 ? 更新時間: 2023-01-23 編程語言

一、paste命令使用方法

1.1 paste命令作用

paste命令用于合并文件行

1.2 paste命令選項

  • -d: 自定義間隔符,默認(rèn)為tab
  • -s:串行處理,非并行

二、paste命令使用實例

首先準(zhǔn)備兩個文件demo1.conf和demo2.conf,其中demo1.conf內(nèi)容如下:

name
domain
ip
area
user
password
role

demo2.conf內(nèi)容如下

test
test
127.0.0.1
china
admin
admin
admin

2.1 將兩個文件,按照行合并

如下,此時將兩個文件按照行合并,同時中間默認(rèn)使用tab間隔,同時將結(jié)果打印出來

[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命令是不會改變源文件的,此時查看兩個文件如下,可以發(fā)現(xiàn)內(nèi)容確實沒有改變。

[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]#

如果希望將合并結(jié)果保存起來則可以使用重定向符號,如下所示

[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參數(shù)指定間隔符,如下所示指定使用等號間隔

[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 將兩個文件串行合并

所謂串行合并,就是把第一個文件的內(nèi)容放在第一行,把第二個文件的內(nèi)容放在第二行,通過-s 參數(shù)實現(xiàn),如下所示,可以發(fā)現(xiàn),這種在打印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]#

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

欄目分類
最近更新