13

How do I join two files vertically without any separator? I tried to use paste -d"" a b, but this just gives me a.

Sample file:

000    0   0   0
0001000200030004
  10  20  30  40
    2000    4000
            .123
            12.1
1234234534564567
Tomas Greif
  • 349
  • 1
  • 4
  • 12

2 Answers2

21

paste use \0 for null delimiter as defined by POSIX:

paste -d'\0' file1 file2

Using -d"" a b is the same as -d a b: the paste program sees three arguments -d, a and b, which makes a the delimiter and b the name of the sole file to paste.

If you're on a GNU system (non-embedded Linux, Cygwin, …), you can use:

paste -d "" file1 file2

The form -d "" is unspecified by POSIX and can produce errors in other platforms. At least BSD and heirloom paste will report no delimiters error.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
cuonglm
  • 150,973
  • 38
  • 327
  • 406
  • 3
    Be careful when trying to derive something from the behavior from the so called "heirloom" tools. `paste` from this suite was written by Gunnar Ritter and is unrelated to the UNIX sources.The Bourne Shell from that suite was derived from the OpenSolaris Bourne Shell, but has it's own bugs as a result from a quick and hacky port to the deficits in Linux (e.g. an incompatible wait() implementation), check `(exec ps)` to verify a hang that is not present in the original and that is not present in my portable Bourne Shell. – schily Sep 07 '15 at 08:41
  • BTW: paste on Solaris before ~April 2010 gives a "no delimiter" error with `paste -d '' file1 file2` but since then, paste is the paste implementation taken from David Korn and this permits -d "". – schily Sep 07 '15 at 08:47
  • @schily: What do you mean "derive"? I mention heirloom `paste` because I had it and can test with it, I don't use it for "standard" or anything else. – cuonglm Sep 07 '15 at 13:15
  • @schily: And also I have tested with Solaris 11, its `paste` gave *no delimiters* error for `paste -d ""`, too. – cuonglm Sep 07 '15 at 13:32
  • Many people believe that tools with the brand "heirloom" are from original UNIX sources, but heirloom paste is not. – schily Sep 07 '15 at 14:07
  • @schily: Yeap, I also used to think that, but changed my mind after read your answer in this site and played with schily tools chest b-). And you see I don't use the standard or something similar with heirloom tools chest anymore. Anyway, feel free to make the edit or raise your own answer to make it better. – cuonglm Sep 07 '15 at 14:12
6

The solution is:

paste -d "\0" a b
Tomas Greif
  • 349
  • 1
  • 4
  • 12