Paste command in Linux

Source: Internet
Author: User
In Linux, the paste command-general Linux technology-Linux programming and kernel information. The following is a detailed description. Cut is used to extract data columns or fields from text files or standard output, and then paste can paste the data to form related files.

When pasting data from two different sources, you must first classify the data and ensure that the number of lines of the two files is the same. Paste places the information of different lines in one row. By default, paste is used to separate different texts in a new line with spaces or tabs. Unless the-d option is specified, it will become a domain separator.

Paste format:
Paste-d-s-file1 file2

The options are as follows:
-D specifies the domain separator different from the space or tab key. For example, use @ to separate domains and use-d @.
-S merges each file into rows instead of by row.
-Use standard input. For example, ls-l | paste indicates that the output is only displayed in a column.

Example:
Wangnc> pg pas1
ID897
ID666
ID982
Wangnc> pg pas2
P. Jones
S. Round
L. Clip

The basic paste command is used to paste the files pas1 and pas2 into two columns:

Wangnc> paste pas1 pas2
ID897 P. Jones
ID666 S. Round
ID982 L. Clip

You can specify which column is first pasted by swapping the file name:

Wangnc> paste pas2 pas1
P. Jones ID897
S. Round ID666
L. Clip ID982

To create a domain separator different from the space or tab key, use the-d option. The following example uses a colon as the domain separator.

Wangnc> paste-d: pas2 pas1
P. Jones: ID897
S. Round: ID666
L. Clip: ID982

You can use the-s option to merge two rows instead of pasting them by row. In the following example, the first line is pasted as the ID number, and the second line is the name.

Wangnc> paste-s pas1 pas2
ID897 ID666 ID982
P. Jones S. Round L. Clip

The paste command also has a very useful option (-). That is, the data is read once from the standard input for each. Use space as the domain separator to display the directory list in a 6-column format. The method is as follows:

Wangnc> ls/etc | paste-d ""------
Manpath path SHLIB_PATH SnmpAgent. d/TIMEZONE X11/
Acct/aliases @ arp @ audeventstab audomon @ auto_master
Auto_parms.log auto_parms.log.old backup @ backup. cfg bcheckrc @ bootpd @
Bootpquery @ bootptab btmp @ catman @ checklist @ chroot @
Clri @ cmcluster/cmcluster. conf cmom. conf @ convertfs @
Copyright cron @ csh. login d. cshrc @ d. exrc @ d. login @

You can also display the output in a column format:
Wangnc> ls/etc | paste-d ""-
MANPATH
PATH
SHLIB_PATH
SnmpAgent. d/
TIMEZONE
X11/
Acct/
Aliases @
Arp @
Audeventstab
Audomon @
Auto_master
Auto_parms.log
Auto_parms.log.old
Backup @
Backup. cfg
Related Article

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.