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