FactorPad
Build a Better Process

Linux paste Command Summary with Examples

Linux 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.
face pic by Paul Alan Davis, CFA
Updated: February 23, 2021
In this tutorial on Linux paste, 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 Tip Next

/ factorpad.com / tech / linux-essentials / paste-command.html


An ad-free and cookie-free website.


Examples of the Linux paste Command

Beginner

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

Video Tutorial

Videos can also be accessed from the Linux Essentials Playlist on YouTube.

Linux paste Command Summary with Examples (3:41)

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.

Common Linux paste Options
-options description
--help Print help screen
-d, --delimiters=LIST Use characters from LIST as delimiters

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.

Demonstration

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 our YouTube Channel and follow @factorpad on Twitter to receive updates.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / paste-command.html


linux paste command
paste linux
linux paste
unix paste
paste unix
linux paste examples
paste files
paste command
linux combine two files
linux merge files
rearrange data in linux
paste command syntax
paste command summary
linux paste options
linux paste tutorial
man paste
shell paste
linux paste examples

A newly-updated free resource. Connect and refer a friend today.