John Doe John Doe - 7 months ago 20
Bash Question

How to read lines from multiple files using bash?

I have three files, lets call them fileA fileB and fileC.

fileA:

This
sentence
to


fileB:

is
I
write


fileC:

the
want
.


Is there a way to loop through fileA then fileB then fileC etc. to show

This is the sentence I want to write .


in another text file?

Answer

If you don't need everything on one line, this will do:

$ paste fileA fileB fileC
This    is      the
sentence        I       want
to      write   .

If you want it all on one line,

$ echo $(paste fileA fileB fileC)
This is the sentence I want to write .