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.


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
  • note that column is likely to break things for files that don't have the same number of lines. – peterph Feb 3 '15 at 19:49
  • @peterph: yes, edited. – heemayl Feb 3 '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 3 '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 4 '15 at 13:38

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.