Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to use the paste command to process strings in Linux

Shulou Source: shulou.com Published: 2022-06-01 16:04:04 09月28日 Update

This article introduces how to use the paste command to deal with strings in Linux, the content is very detailed, interested friends can refer to, I hope it can be helpful to you.

Name: paste

Location: / usr/bin/paste

Permissions: all users

Function: two corresponding lines of multiple files are pasted together

Usage: paste [OPTION]. [FILE]...

Options:

-d connects the delimiter of two lines. The default is [TAB] as the delimiter.

If the file is partially written, then it represents the data from the standard input

The code is as follows:

$cat a

Pa:11:a

Sa:32:c

App:5:b

Stort:1:d

Pear:4:aa

Hello:3:f

$cat b

Acccc

A b

C

B dd

D aa

A c

B

F dd

$paste a b

Pa:11:an acccc

Sa:32:c a b

App:5:b c

Stort:1:d b dd

Pear:4:aa d aa

Hello:3:f a c

B

F dd

The code is as follows:

$paste-d "," a b specifies a comma as the delimiter

Pa:11:a, acccc

Sa:32:c,a b

App:5:b, c

Stort:1:d,b dd

Pear:4:aa,d aa

Hello:3:f,a c

, b

, f dd

Example of file Writing -, specifying @ as the delimiter

The code is as follows:

$cat b | paste-d "@" a-

Pa:11:a@ acccc

Sa:32:c@a b

App:5:b@ c

Stort:1:d@b dd

Pear:4:aa@d aa

Hello:3:f@a c

@ b

@ f dd

On how to use the paste command in Linux to deal with strings is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Delimiters codes commands characters strings processing content more help good location function examples interests names multiple guys buddies data files Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn NVidia Microsoft Shulou Information Redmi