Combine two files column-wise in Ubuntu?

4

3

I have two files: one is like

preface
Introduction
chapter 1

the other is like

1
2
3

I was wondering how to column-wise combine the two files into one:

preface 1
Introduction 2
chapter 1 3

by using some utilities, such as awk, sed, available in Ubuntu?

Thanks and regards!

Tim

Posted 2011-07-07T13:58:49.210

Reputation: 12 647

For such file manipulation I would look for the join command. It requires a common field though, but you could add one like line number, no ? – Julien – 2011-07-07T14:08:56.507

@Julien: How do you do with join? – Tim – 2011-07-07T14:36:07.203

Answers

7

paste fileone filetwo

Use -d to specify delimiter.

user1686

Posted 2011-07-07T13:58:49.210

Reputation: 283 655

Thanks! I just found that pr -t -m firstfile secondfile can also do the similar job. Are there differences between the two methods? – Tim – 2011-07-07T18:31:52.333