Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have tried to get the 2 files output in a single file. I have tried below command:

cat file1 file2

but here file2 data is appending to file1.

What I need is file1 1st line followed by file2 first line, and file1 second line followed by file2 second line etc.

Can anybody tell me how to do this in a simple way?

share|improve this question

1 Answer 1

There's an app for that!

$ cat file1
file1 line1
file1 line2

$ cat file2
file2 line1
file2 line2

Now, if you pass these files as arguments to paste:

$ paste -d' ' file1 file2
file1 line1 file2 line1
file1 line2 file2 line2

If by "file1 1st line followed by file2 first line, and file1 second line followed by file2 second line etc.", you mean that you want a new line between each line pasted, simply adjust the -d (delimiter) option.

$ paste -d'\n' file1 file2
file1 line1
file2 line1
file1 line2
file2 line2
share|improve this answer
    
+1 for "There's an app for that!" –  Celada Jul 3 at 19:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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