1

I have four text files each containing a single field. I want to convert them into a single text file with four fields (one from each file). How can I do this using shell scripting.

Syed Moez
  • 307
  • 1
  • 4
  • 17

2 Answers2

3

This should do:

paste file_1 file_2 file_3 file_4

If you want pretty printing (given that the number of lines are same for all the files), then:

paste 1 2 3 4 | column -t
heemayl
  • 56,300
  • note that column is likely to break things for files that don't have the same number of lines. – peterph Feb 03 '15 at 19:49
  • @peterph: yes, edited. – heemayl Feb 03 '15 at 19:50
  • @peterph - depends what switches his/her version of column accepts... see glenn jackman's answer here - it works fine with files that don't have the same number of lines. – don_crissti Feb 03 '15 at 21:11
  • @don_crissti "... is likely* to break things..."* You'll have to fiddle with it to make sure things will be what you want them to be. – peterph Feb 04 '15 at 13:38
2

The paste command does exactly what you're looking for, and the good news is that it's POSIX-standard, so it's available effectively everywhere.

aecolley
  • 2,177