Common command collation on Linux (ii)--paste

Source: Internet
Author: User

The previous article organized several basic common uses of cat instructions, this time finishing the basic usage of the Paste directive.

    1. Cat
    2. Paste
    3. Cut
    4. 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.

    • Direct stitching
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

    • Remove all line breaks
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.