Linux Common Commands--paste

Source: Internet
Author: User
Tags gopher

1. Functions: Merging the columns of a file

2. Usage: Paste [parameters] File

3. Parameters:

-D,--delimiters Specifies the spacer,

- s,--serial combine multiple rows of data into multiple columns

4. Example

Select the first and last columns of the/etc/passwd file as raw data, test with the Paste command, and first extract the first column and the last column from the/etc/passwd file:

[[email protected] ~]$ cat/etc/passwd |awk-f ":" ' {print $} ' >user_name.txt

[[email protected] ~]$ cat/etc/passwd |awk-f ":" ' {print $NF} ' >user_login.txt

[email protected] ~]$ head user_* #查看文件内容


Example 1: Merging user_name,user_login two columns

[email protected] ~]$ paste User_name.txt user_login.txt|head-5

Root/bin/bash

Bin/sbin/nologin

Daemon/sbin/nologin

Adm/sbin/nologin

Lp/sbin/nologin

Specify the delimiter as ","

[email protected] ~]$ paste-d "," User_name.txt user_login.txt|head-5

Root,/bin/bash

Bin,/sbin/nologin

Daemon,/sbin/nologin

Adm,/sbin/nologin

Lp,/sbin/nologin

Example 2: Row to Column

The file's row to column, one file is 1 lines.

A file row to column:

[email protected] ~]$ paste-s user_name.txt

Root bin Daemon adm LP sync shutdown halt mail UUCP operator Games Gopher FTP No Body Dbus oprofile vcsa hsqldb saslauth postfix sshd MySQL NTP

[email protected] ~]$ paste-s user_name.txt |wc-l

1

Two files are followed by row-to-column and are:

[email protected] ~]$ paste-s user_name.txt user_name.txt

Root bin Daemon adm LP sync shutdown halt mail UUCP operator Games Gopher FTP No Body Dbus oprofile vcsa hsqldb saslauth postfix sshd MySQL NTP

Root bin Daemon adm LP sync shutdown halt mail UUCP operator Games Gopher FTP No Body Dbus oprofile vcsa hsqldb saslauth postfix sshd MySQL NTP

[email protected] ~]$ paste-s user_name.txt user_name.txt |wc-l

2

After the file is merged, the row goes to the column:

[email protected] ~]$ paste-d user_name.txt user_name.txt|paste-s |wc-l

1


Linux Common Commands--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.