Merge two files by column in Linux and combine Columns

Source: Internet
Author: User

Combine two files by column in Linux: _ su ranxu's blog _ Baidu Space

Merge two files by column in Linux and combine Columns

Both awk and cut can divide a file with multiple columns into single-column files, which in turn can be usedThe paste command combines multiple single-column files into one multi-column file.

 

Command example:

Paste names numbers combines two files and uses the tab key to separate them.
Paste-d '+ 'names numbers merge the two files and separate them with the' + 'symbol.
Paste-s names combines multiple rows of data into one row separated by the tab key

 

Parameter description:Column of the merged file.
Syntax: paste [-S] [-D] [-- help] [-- version] [file...]
Note: The paste command merges each file in a column-to-column manner.
Parameters:
-D or -- delimiters = Replace the escape character with the specified delimiter.
-S or -- serial string columns are processed rather than in parallel.
-- Help Online Help.
-- Version: displays help information.

Scenario:

$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 Merge two files and separate them with the tab key.
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., Bensonurst
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., Bensonurst (212) 555-7741
Fred 17 E. 25th Street, New York (212) 555-0040
$ Paste-D ''names ses SSEs numbers they are separated by the specified'' symbol
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., Bensonurst (212) 555-7741
Fred 17 E. 25th Street, New York (212) 555-0040
$ Paste-s names combines multiple rows of data into one row, which are separated by the tab key.
Tony Emanuel Lucy Ralph Fred

 

References:

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

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.