Linux按列合并兩檔案,列的拼合

來源:互聯網
上載者:User

Linux按列合并兩檔案,列的拼合_蘇冉旭的部落格_百度空間

Linux按列合并兩檔案,列的拼合

awk 和 cut 都能把一個多列檔案差分成單列檔案,那麼反過來也可以用paste命令把多個單列檔案拼合成一個多列檔案。

 

命令舉例:

paste names numbers   將兩個檔案合并用tab鍵分隔開
paste -d'+' names numbers   將兩個檔案合并指定'+'符號隔開
paste -s names        將多行資料合併到一行用tab鍵隔開

 

參數說明:合并檔案的列。
語  法:paste [-s][-d ][--help][--version][檔案...]
補充說明:paste指令會把每個檔案以列對列的方式,一列列地加以合并。
參  數:
-d或--delimiters=  用指定的佔空間字元取代跳格字元。
-s或--serial  串列進行而非平行處理。
--help  線上協助。
--version  顯示協助資訊。

使用情景:

$ cat names
Tony
Emanuel
Lucy
Ralph
Fred
gan.cublog.cn

$ cat numbers
(307) 555-5356
(212) 555-3456
(212) 555-9959
(212) 555-7741
(212) 555-0040

$ paste names numbers 將兩個檔案合并,他們中間用tab鍵分隔開
Tony (307) 555-5356
Emanuel (212) 555-3456
Lucy (212) 555-9959
Ralph (212) 555-7741
Fred (212) 555-0040
gan.cublog.cn
$ cat addresses
55-23 Vine Street, Miami
39 University Place, New York
17 E. 25th Street, New York
38 Chauncey St., Bensonhurst
17 E. 25th Street, New York
gan.cublog.cn
$ paste names addresses numbers
Tony 55-23 Vine Street, Miami (307) 555-5356
Emanuel 39 University Place, New York (212) 555-3456
Lucy 17 E. 25th Street, New York (212) 555-9959
Ralph 38 Chauncey St., Bensonhurst (212) 555-7741
Fred 17 E. 25th Street, New York (212) 555-0040
$ paste -d' ' names addresses numbers 他們中間用指定的' '符號隔開
Tony 55-23 Vine Street, Miami (307) 555-5356
Emanuel 39 University Place, New York (212) 555-3456
Lucy 17 E. 25th Street, New York (212) 555-9959
Ralph 38 Chauncey St., Bensonhurst (212) 555-7741
Fred 17 E. 25th Street, New York (212) 555-0040
$ paste -s names 將多行資料合併到一行,他們間用tab鍵隔開
Tony Emanuel Lucy Ralph Fred

 

參考資料:

[1]: http://hi.baidu.com/quanzhou722/blog/item/6ecb30a72513ec8fd043584e.html

[2]: http://hi.baidu.com/pinemoon/blog/item/aae173aff5c021034b36d635.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.