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:

1;3;F;100


File 2:

2;'john'


How to get an output like this?

1;3;F;100;2;'john'


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
1;3;F;100;2;'john'

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