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命令是不會改變源文件的,此時查看兩個文件如下,可以發(fā)現(xiàn)內容確實沒有改變。
[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]#
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 將兩個文件串行合并
所謂串行合并,就是把第一個文件的內容放在第一行,把第二個文件的內容放在第二行,通過-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]#
到此這篇關于Linux paste命令使用詳解的文章就介紹到這了,更多相關Linux paste命令使用內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Linux batch命令詳解(在系統(tǒng)不繁忙的時候執(zhí)行定時任務)
batch命令 用于在指定時間,當系統(tǒng)不繁忙時執(zhí)行任務,用法與at相似,這篇文章主要介紹了Linux batch命令(在系統(tǒng)不繁忙的時候執(zhí)行定時任務),需要的朋友可以參考下2024-02-02Linux?Shell腳本多命令執(zhí)行邏輯的示例詳解
Linux?中可以使用分號";“、雙and號”&&“和雙豎線”||"來連接多個命令。根據(jù)場景的不同適當?shù)氖褂煤线m的符號,感興趣的小伙伴可以了解一下2022-10-10