Linux paste命令用法匯總
一、paste命令使用方法
1.1 paste命令作用
paste命令用于合并文件行
1.2 paste命令選項(xiàng)
- -d: 自定義間隔符,默認(rèn)為tab
- -s:串行處理,非并行
二、paste命令使用實(shí)例
首先準(zhǔn)備兩個(gè)文件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 將兩個(gè)文件,按照行合并
如下,此時(shí)將兩個(gè)文件按照行合并,同時(shí)中間默認(rèn)使用tab間隔,同時(shí)將結(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命令是不會(huì)改變?cè)次募?,此時(shí)查看兩個(gè)文件如下,可以發(fā)現(xiàn)內(nèi)容確實(shí)沒有改變。
[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é)果保存起來則可以使用重定向符號(hào),如下所示
[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 將兩個(gè)文件按照行合并,同時(shí)指定間隔符
通過-d參數(shù)指定間隔符,如下所示指定使用等號(hào)間隔
[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 將兩個(gè)文件串行合并
所謂串行合并,就是把第一個(gè)文件的內(nèi)容放在第一行,把第二個(gè)文件的內(nèi)容放在第二行,通過-s 參數(shù)實(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]#
到此這篇關(guān)于Linux paste命令使用詳解的文章就介紹到這了,更多相關(guān)Linux paste命令使用內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Linux batch命令詳解(在系統(tǒng)不繁忙的時(shí)候執(zhí)行定時(shí)任務(wù))
batch命令 用于在指定時(shí)間,當(dāng)系統(tǒng)不繁忙時(shí)執(zhí)行任務(wù),用法與at相似,這篇文章主要介紹了Linux batch命令(在系統(tǒng)不繁忙的時(shí)候執(zhí)行定時(shí)任務(wù)),需要的朋友可以參考下2024-02-02Linux?Shell腳本多命令執(zhí)行邏輯的示例詳解
Linux?中可以使用分號(hào)";“、雙and號(hào)”&&“和雙豎線”||"來連接多個(gè)命令。根據(jù)場景的不同適當(dāng)?shù)氖褂煤线m的符號(hào),感興趣的小伙伴可以了解一下2022-10-10VPS自動(dòng)備份數(shù)據(jù)庫到FTP的腳本代碼
示例的文件目錄結(jié)構(gòu):我在/home下操作,自動(dòng)腳本名稱為backup.sh(放置于/home目錄下),VPS本地本分目錄為/home/backup2013-01-01一篇教會(huì)你寫90%的shell腳本(入門小結(jié))
這篇文章主要介紹了一篇教會(huì)你寫90%的shell腳本,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05