5

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)?

1
  • 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, 2010 at 18:03

2 Answers 2

12

You want paste.

paste fileA fileB > fileAB
1
  • Yay, that's exactly what I was looking for. Thanks!
    – Tamás
    Oct 21, 2010 at 15:35
0

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)

You must log in to answer this question.

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