Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking for a solution for the following simple problem. I have two files, fileA and fileB. Each file contains only one word per line, and they contain exactly the same number of lines.

I would like to create a new file called fileAB, where the i-th line contains the i-th line of fileA, a Tab separator character, and then the i-th line of fileB. I know how to do it in Python or other scripting languages, but it would be nice to have a bash one-liner for that.

Is it possible to do this in bash or any other Unix shell, using the tools that are usually available on the command line (e.g., sed, awk and such)?

share|improve this question
Ignacio's answer is of course excellent, but it's worth mentioning that python is availbable on the command line and is in principle no less of a "one liner" than sed or paste. – CarlF Oct 21 '10 at 18:03
up vote 12 down vote accepted

You want paste.

paste fileA fileB > fileAB
share|improve this answer
Yay, that's exactly what I was looking for. Thanks! – Tamás Oct 21 '10 at 15:35

parallel --xapply -j1 -a file_1 -a file_2 echo {} > file_12

or an alternative style

parallel --xapply -k echo :::: file_1 :::: file2 > file_12

The shorter file will wrap its lines to match the length of the longer file.(if you want this behavior)

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .