The previous article organized several basic common uses of cat instructions, this time finishing the basic usage of the Paste directive.
- Cat
- Paste
- Cut
- Grep
Paste
Paste can be simply understood to combine the contents of two files in columns, and the cat command directly to the different files in sequence, the paste can be very fast to the contents of two files in the file order from left to right, for example, the content of file 1 is:
A
B
C
D
The contents of document 2 are:
1
2
3
4
Then the result after paste is:
A 1
B 2
C 3
D 4
You can even insert a spacer symbol into the middle when stitching, and here's a list of common uses.
Paste File1 file2 > Result
The above instruction will file1 and file2 content in the column after stitching, deposited in the result file, if not add > result, then directly displayed in the terminal
- Use the specified symbol to separate the contents of each file when stitching
Paste-d ': ' File1 file2
The results are similar
A:1
B:2
C:3
D:4
-D after using double quotation marks and single quotes even without the result of quotation marks, and can only specify one character, you write a large string of-D "::::----" Still only the first character will be taken as a delimiter
Paste File1-s
This command will delete all line breaks, that is, all lines of file1 are spelled into a whole line.
Or it can be two files
Paste File1 file2-s
The result of the execution is that the contents of the two files are stored in a single line, then output in file order, the final result is two lines, each line corresponds to a file
can also be used in combination with-D, equivalent to replacing newline characters of the original file contents with the specified delimiter
Paste File1-s-D:
The results are similar:
A:b:c:d
- Specify the number of reads from standard input
This is a very special use, mainly in combination with other directives, first seen in Http://blog.csdn.net/andy572633/article/details/7214126 's article, he gives the following usage:
ls/etc | Paste-d"" ------
First use the LS command output/etc directory, and then the pipeline to the Paste command, the output will be 6 columns; Note that the middle of the double quotation mark is a space, indicating that the following-number is separated by a space
I tried it myself. Cat Combo with similar results
Cat File1 | Paste-d"" --
A b
C D
Resources:
http://blog.csdn.net/andy572633/article/details/7214126
Common command collation on Linux (ii)--paste