Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have 2 files. I want to merge them.

File1 contents:


File2 contents:


Combined File should be:

share|improve this question
Its should ne new line for def – Ocean Mar 19 '13 at 6:36

This is a useful1 use of cat:

$ cat File1 File2 > CombinedFile


1. As opposed to the useless use of cat

share|improve this answer
I think he meant to take one line each time from both file, and merge them, not to append one file to another. – warl0ck Mar 19 '13 at 6:57
"Did you mean: useful" :) – l0b0 Mar 19 '13 at 16:34
@warl0ck Then he should have stated that. – Bernhard Mar 19 '13 at 18:36

This perl scriptlet does this deed:


open my $f1, "<", $ARGV[0];
open my $f2, "<", $ARGV[1];

do {
    $line1 = <$f1>;
    print $line1 if(defined($line1));
    $line2 = <$f2>;
    print $line2 if(defined($line2));
} while(defined($line1) && defined($line2));
while(<$f1>) {
while(<$f2>) {

Call as e.g. perl splice file1 file2 > spliced. Has no error checking, just a thowaway script.

share|improve this answer

Your Answer


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.