How to merge two files using the paste command of linux
This article mainly introduces how to use linux's paste command to merge two files, which has certain reference value and can be used for reference by friends who need it. Let's take a look at it with me.
The paste command merges each file column by column, column by column, which is equivalent to pasting the contents of two different files together to form a new file.
Note: the paste default paste method pastes as columns, but it is not impossible to paste as rows. Add the-s option to paste in rows.
Syntax format: paste [parameters] [File 1] [File 2]
Common parameters:
The delimiter of the-d default field is the space or tab key, set the new field delimiter-s paste each file into a line-read data from standard input
Reference example
Paste file_2 and file_2 into a new file:
[root@linuxcool ~] # cat file_1
Aaa
Bbb
Ccc
Ddd
Eee
[root@linuxcool ~] # cat file_2
AAA
BBB
CCC
DDD
EEE
[root@linuxcool ~] # paste file_1 file_2
Aaa AAA
Bbb BBB
Ccc CCC
Ddd DDD
Eee EEE
Set the domain delimiter to: paste into a new file:
[root@linuxcool ~] # paste-d: file_1 file_2
Aaa:AAA
Bbb:BBB
Ccc:CCC
Ddd:DDD
Eee:EEE
Paste each file into a line:
[root@linuxcool ~] # cat file_1
Aaa
Bbb
Ccc
Ddd
Eee
[root@linuxcool ~] # cat file_2
AAA
BBB
CCC
DDD
EEE
[root@linuxcool] # paste-d:-s file_1 file_2
Aaa:bbb:ccc:ddd:eee
AAA:BBB:CCC:DDD:EEE
Read data from standard input, showing 5 file names per line:
[root@linuxcool ~] # ls | paste-d ""-
Anaconda-ks.cfg dir_1 file1 file_1 file_1.db
File_2 file_3 file_4 file_5 file_6
File.db file_hobby_1 file_hobby.db file_hobby_sort.db file_sort.db
Initial-setup-ks.cfg testfile above is how to use linux's paste command to merge the details of the two files, after reading it, do you have anything to gain? If you want to know more about it, welcome to the industry information!