This original article belongs to "Linux greenhouse" blog, the blog address is http://roclinux.cn. The author of the article is rocrocket.
In order to prevent the vicious reproduction of some websites, special in each article before adding this information, but also hope that readers understand.
===
[Start of body]
In the previous article in this series, which covers the Cut command (five-minute series 19 of the Cut Command-linux command), this paste command, described in this article, is a dedicated and cut-to-dry command that is designed to piece together several files.
1 What is the paste principle?
This is very simple, and the principle of cut is almost the same, the corresponding lines of several files are connected with tabs, and output to the standard output.
The simplest way to use paste is to:
[email protected] programming]$ cat P1.txt
123[Rocrocket@rocrocket programming]$cat p2.txtabc [Rocrocket @rocrocket programming]$ paste p1.txt p2.txt1 a2 b3 C [rocrocket@ Rocrocket programming]$ paste p1.txt p2.txt| sed -n l 1\ta$2\tb$3\tc$ |
See the tab, it is the default spacer.
2 The above example is two files, what about the three files?
Of course I can. Let's take a look at examples:
[Rocrocket@rocrocket programming]$cat P3.TXTIIIIII [rocrocket@ Rocrocket programming]$ paste p1.txt p2.txt p3.txt1 a i2 b II 3 c iii[rocrocket @rocrocket programming]$ paste p3.txt p2.txt p1.txti a 1ii b 2iii c 3 |
The result of the visible paste is related to the order of the file list.
3 I do not want to use a tab to the interval, I want to use an asterisk (*), can I?
It's okay! You can set a spacer with the-D symbol, which is no different from cut. Take a look at the example:
[Rocrocket@rocrocket Programming' * ' p3.txt p2.txt p1.txti*a*1II*b*2III*c *3 |
Note that it is important to enclose the asterisk in quotation marks (both single quotation marks), otherwise the shell expands the asterisk to the list of files in the current directory Oh, be careful.
4 I have seen the man Paste command, which mentions a-s option, I do not understand what is meant?
This is a good explanation, continue with the above example and look at this command:
[Rocrocket@rocrocket Programming"*" P3.txt p2.txt p1.txti *ii *iiia*b*c1*2 *3 |
Oh, understand, S is to each file as a processing unit, which all the lines in the-D set of spacers to form a large line, output to the standard output.
Bottom line: Paste is to combine files.
"Paste command"-linux command five-minute series 20