Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I append lines from one file to the end of each line of another file?

Tags:

bash

append

line

Suppose I have two files:

cat
dog
baboon
feline
canine
primate

I want to append the lines from one file at the end of another file after adding a space. I know a way to do this using a for loop in bash, but I think there is a single command that can do this sort of thing, and I just can't remember it.

The output should look like:

cat feline
dog canine
baboon primate
like image 888
donatello Avatar asked Dec 05 '10 09:12

donatello


1 Answers

paste --delimiter=' ' file1 file2

Note: the result will be written to stdout. If you want to store the result in a file, use a redirection operator:

paste --delimiter=' ' file1 file2 > outputfile

Run man paste for more information about the command.

like image 189
Lekensteyn Avatar answered Oct 05 '22 23:10

Lekensteyn