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