Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

merge contents of two files into one file in bash

I have two files which has following contents

File1

Line1file1
Line2file1
line3file1
line4file1

File2

Line1file2
Line2file2
line3file2
line4file2

I want to have these file's content merged to file3 as

File3

Line1file1
Line1file2
Line2file1
Line2file2
line3file1
line3file2
line4file1
line4file2

How do I merge the files consecutively from one file and another file in bash?

Thanks

like image 684
user3784040 Avatar asked Dec 06 '22 22:12

user3784040


2 Answers

You can always use paste command.

paste -d"\n" File1 File2 > File3
like image 157
shauryachats Avatar answered Dec 29 '22 23:12

shauryachats


$ cat file1
Line1file1
Line2file1
line3file1
line4file1

$ cat file2
Line1file2
Line2file2
line3file2
line4file2

$ paste -d '\n' file1 file2 > file3

$ cat file3
Line1file1
Line1file2
Line2file1
Line2file2
line3file1
line3file2
line4file1
line4file2
like image 37
Marco Baldelli Avatar answered Dec 29 '22 23:12

Marco Baldelli