in

LinuxLinux

Paste Command in Linux: Syntax, Commands & Examples!

How to Use Paste Command in Linux?

Paste Command in Linux

P

aste Command in Linux: Paste command is mainly used to merge lines horizontally  of two or more different files in Linux. In this article, we share information about Paste Command syntax, options & examples.

Paste command prints lines consisting of the sequentially corresponding lines of each file specified as an argument & separated by tabs

Jump To:

Paste Command Syntax:

The basic syntax of Paste command is,

$paste [OPTIONS] [FILE1] [FILE2]

The above mention is the basic syntax of the paste command in Linux. You need to replace the FILE1 and FILE2 with your file names. The paste command will merge the lines horizontally and separated by tabs.

Paste Command Options:

To print the available options in paste command, use the below command,

$paste --help

The above command will print the following output,

[email protected]:~$ paste --help
Usage: paste [OPTION]... [FILE]...
Write lines consisting of the sequentially corresponding lines from
each FILE, separated by TABs, to standard output.

With no FILE, or when FILE is -, read standard input.

Mandatory arguments to long options are mandatory for short options too.
  -d, --delimiters=LIST   reuse characters from LIST instead of TABs
  -s, --serial            paste one file at a time instead of in parallel
  -z, --zero-terminated    line delimiter is NUL, not newline
      --help     display this help and exit
      --version  output version information and exit

GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Full documentation at: <https://www.gnu.org/software/coreutils/paste>
or available locally via: info '(coreutils) paste invocation'
[email protected]:~$ 

The above output lists the available options that can be used with paste commands.

Check this too  Whereis Command in Linux: Syntax, Commands & Examples.

How to use Paste Command:

Paste command is a command-line utility in Linux. If no input files are mentioned the paste command will use the default or standard input. You can understand the working of the paste command using the below example.

Let us consider two files having a name “File1” & “File2”:

File1 contains
1
2
3
4
5
File2 contains
6
7
8
9
10

Paste command helps us to merge those two files by merging the arguments horizontally and separated by tabs.

$paste File1 File2

The output of the above command is,

Output
1 6
2 7
3 8
4 9
5 10

If you don’t want to print the output in screen and then use the “>” operator to print the output in the new file. To do this follow the below command,

$paste File1 File2 > Output_file

The “-d” option helps you to print the output with user-defined characters by replacing the tabs. If you want to use the “#” character instead of tabs in the output and then use the below command,

$paste -d '#' File1 File2

The above command prints the output,

Output
1#6
2#7
3#8
4#9
5#10

The output shows the tabs have been replaced with the user-defined # character and merged horizontally. Use the below command to print the output as a new file with user-defined character.

$paste -d '#' File1 File2 > Output_file
You can use two delimeters at a single time, follow the below example command:

$paste -d '#>' File2 File1 File1 > Output_file

The above command prints the output:

Output
6#1>6
7#2>7
8#3>8
9#4>9
10#5>10

The output shows that, two delimiters have been used and replaced the tabs while merging horizontally.

Check this too  How to Change User Password in Ubuntu 18.04 LTS & 19.04 Disco Dingo

The “-s” option along with paste command will print the output lines of one file at a time instead of one line from each file.

The example paste command along with -s option,

$paste -s File1 File2

The output of the above command is,

Output
1 2 3 4 5
6 7 8 9 10

The “-Z” options used to nullify the delimeter while merging the files. This is how paste command works in Linux.

Verdict:

That’s it. In this article, we shared the information about using the Paste command with options. If you have any queries related to this article and then feel free to comment us below.

Article Review
  • Article Explanation
  • Commands Provided
  • Syntax Provided
  • Examples Provided
4.8

Summary

For more articles, Kindly visit our HomePage

Leave a Reply

Your email address will not be published. Required fields are marked *

Written by Julian

Hello Folks! I'm Julian, Promoted to the Content writer for the category of Commands & Web Apps in Tec Robust. Enjoy my content & Learn more Linux Commands!

Contact me:
tecrobust [@] gmail.com
Sub: Message to Julian

Mumble Ubuntu

Mumble Ubuntu- Install Mumble on Ubuntu 18.04 LTS & 19.04

Synaptic Package Manager

Synaptic Package Manager Ubuntu- Install on Linux Ubuntu 18.04 LTS/ 19.04