Tag: script
[Copyright statement: reprinted. Please retain the Source: blog.csdn.net/gentleliu. Mail: shallnew at 163 dot com]
It can be seen from the literal that the paste command and the cut command have the opposite function. The cut command extracts fields from the file line, while the paste command merges the file line information into one line.
The paste command is used as follows:
paste -d -s -file1 file2
The-s option combines the file rows into one row.
For example, the following files are available:
# paste 1.filenameallenbobchrisdyao
# paste 1.file -s name allen bob chris dyao
This command combines each line of the file into one line separated by the tab key.
-D specifies the separator. For example:
# paste -s -d - 1.file name-allen-bob-chris-dyao
Paste can splice multiple files by column, as shown below:
# paste 1.file 2.file 3.filename sex ageallen mail 25bob female 27chris male 56dyao mail 14 female 19
You can also splice multiple files by column:
# paste 1.file 2.file 3.file -sname allen bob chris dyaosex mail female male mail femaleage 25 27 56 14 19
Of course, you can also specify the separator Number:
# paste 1.file 2.file 3.file -s -d:name:allen:bob:chris:dyaosex:mail:female:male:mail:femaleage:25:27:56:14:19
Or
# paste 1.file 2.file 3.file -d:name:sex:ageallen:mail:25bob:female:27chris:male:56dyao:mail:14:female:19
Shell text filtering programming (11): paste command