user3449064
user3449064

Reputation: 21

Merge files in Unix per lines

I have two txt files, first one contains:

    000
    111
    222
    333
    444

and the second one contains:

    .

How can I merge this two text files in the unix terminal, so I can get another file that contains:

    .000
    .111
    .222
    .333
    .444

Thanks for your answers

Upvotes: 1

Views: 59

Answers (1)

evil otto
evil otto

Reputation: 10582

The paste command is generally what you're looking for, but it expects both files to have the same number of lines. You can create a file with the same number of lines repeated with something like yes $(cat file2) | head -$(wc -l < file1)

So the whole thing, using bash file substitution:

 paste -d "" <(yes $(cat file2) | head -$(wc -l <file1)) file1

Upvotes: 1

Related Questions