Faster Learning Tutorials

Linux paste command summary with examples

paste allows you to combine lines from two files.
  1. Purpose - Learn what paste is for and how to find help.
  2. Options - Review a few common options and arguments.
  3. Script - Walk through code examples with paste.
  4. A tip - Finish off with one more insight.
Paul Alan Davis, CFA, October 20, 2016
Updated: August 1, 2018
In this tutorial, 37 of 100, below find a 3-4 minute introductory video, a text-based tutorial and all of the code examples from the video.

Outline Back Next

~/ home  / tech  / linux essentials  / paste command

The Linux paste command


Learn to combine lines from two text files at the Linux command line.

Video Tutorial

Linux paste command summary with examples (3:41)

Videos can also be accessed from the YouTube Playlist.

Video Script

The Command and Why You Need It

Our thirty-seventh word, or command to memorize is paste from our category Text.

paste allows you to combine lines from two files.

Recall from video 33, we learned how to cut and now we'll learn how to paste, or more literally add columns from one file to another.

Before we start, it helps to think of commands as mini programs and most follow this structure: command -option(s) argument(s).

The paste command has 4 options, and the arguments include the first file, and the second is what you'd like to add to the first.

Like most commands, help is available with double-dash --help. The option we'll use here is -d because we're using the colon symbol as a delimiter.

So why is paste an important command? Well, for data often stored in spreadsheets or databases, paste offers a way to add fields from other files. And now you know how to do that.


Okay, the best way to embed this in your memory is by typing in your own terminal window.

Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.

Here we go. Let's first take a look at the file we created in the last video using a cat -n, which numbers lines, and it's video36.txt.

$ cat -n video36.txt 1 Oct 4:video05.txt 2 Oct 10:video11.txt 3 Oct 10:video16.txt 4 Oct 12:video19.txt 5 Oct 12:video20.txt 6 Oct 13:video21.txt 7 Oct 13:video23.txt 8 Oct 15:video24.txt 9 Oct 15:video26.txt 10 Oct 15:video27.txt 11 Oct 17:video31.txt 12 Oct 18:video32.txt 13 Oct 18:video33.txt

We have 13 rows, the dates videos were created in this column (middle) and the video text file (third column).

Next, I've created another text file in video37.txt listing the number of YouTube views for each video one year from now, found using my crystal ball, of course ;). Let's look at it with cat -n.

$ cat -n video37.txt 1 6 2 8 3 819302 4 60 5 669821 6 981032 7 69 8 781420 9 9 10 897502 11 8 12 86 13 789123 $ clear

It's thirteen rows, but it isn't useful sitting in a separate file, is it? So let's paste it.

Okay, go optionless with paste and the arguments.

$ paste video36.txt video37.txt Oct 4:video05.txt 6 Oct 10:video11.txt 8 Oct 10:video16.txt 819302 Oct 12:video19.txt 60 Oct 12:video20.txt 669821 Oct 13:video21.txt 981032 Oct 13:video23.txt 69 Oct 15:video24.txt 781420 Oct 15:video26.txt 9 Oct 15:video27.txt 897502 Oct 17:video31.txt 8 Oct 18:video32.txt 86 Oct 18:video33.txt 789123

And we'll see here that the output really isn't ideal.

And last, let's add the -d option with the :, like this, as the delimiter between fields.

$ paste -d ":" video36.txt video37.txt Oct 4:video05.txt:6 Oct 10:video11.txt:8 Oct 10:video16.txt:819302 Oct 12:video19.txt:60 Oct 12:video20.txt:669821 Oct 13:video21.txt:981032 Oct 13:video23.txt:69 Oct 15:video24.txt:781420 Oct 15:video26.txt:9 Oct 15:video27.txt:897502 Oct 17:video31.txt:8 Oct 18:video32.txt:86 Oct 18:video33.txt:789123

This gives us better results.

A Final Tip

Okay now you know how to use paste. And you know the syntax for commands, options and arguments.

One last tip about the paste command. So paste is a handy way of cleaning up tabular data. Hang on tight to see what we do with it next.

Okay, thanks for visiting today. I hope this was a helpful introduction to the paste command.

Learn More About The Series

For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:

What's Next?

It really helps to pair this web content with the videos. Subscribe to the YouTube Channel right here.

  • For the Outline to all 100 tutorials, click Outline.
  • To go back to the sdiff command, hit Back.
  • For the next video on join, click Next.

Outline Back Next

~/ home  / tech  / linux essentials  / paste command

linux paste command
paste linux
linux combine files
linux merge files
linux merge code
linux rearrange data
unix paste
linux add columns
linux paste examples
linux merge text
linux paste files
paste command syntax
man paste
linux paste tutorial
shell paste
linux paste options
rearrange data in linux