jycr753 jycr753 - 24 days ago 7
Linux Question

Combine text files preserving separator and formatting

Is possible to have a sed or cat command to merge two text files? for example:

File 1:


File 2:


How to get an output like this?


Because when I do
cat file1 file2 > file-merged
does created in the wrong format for me.

Answer Source

The paste command will do this. For example:

$ paste -d ';' file1.txt file2.txt

'paste' merges the corresponding lines in both files. The '-d' sets the delimiter added between the lines.