Using the Unix paste command to join files together by column

I can’t believe I didn’t know about command-line utility until very recently. I was doing a little research on some text processing utilities and came across the “paste” command. As a Mac user I have this installed already, and this appears to be a fairly common LInux/Unix tool as well. It’s part of a suite of text processing utilities that are fairly standard. Oddly, I am very familiar with the likes of sed, grep, awk, and so on, and yet have not stumbled upon this.

Anyway, imagine the following files, starting with names.txt:


And numbers.txt:


Then we just run paste:

paste names.txt numbers.txt

And we get this:

Jason   555-1234
Cameron 555-9876
Tim     555-2468

Paste just marries the files up by column, reading from each file. You can supply more than two files.

I don’t have an immediate need for this utility for processing Essbase data, but it just might come in handy someday, so I’m going to keep it in my back pocket. And for you Windows users out there, well, you know the deal: get cygwin or whatever the latest and greatest Unix-on-Windows environment is.

One thought on “Using the Unix paste command to join files together by column

  1. Also a Mac user and have clients on Unix, but have only ever self-taught this stuff, so never get the benefit of a Unix mentor to say “you’re making that harder than it needs to be”. A similar example; I only found cut quite recently, had always used awk instead.

    I do love how quickly I can wrangle huge data files with the Unix tools.

Leave a Reply

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