14

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
3
  • 1
    Are you sure this what you get? paste - d"" a b will paste content from stdin, file named d"", a, b. Commented Sep 7, 2015 at 1:37
  • @cuonglm typo...fixed. Commented Sep 7, 2015 at 1:59
  • You were off by one character: paste -d "" a b. Commented Sep 7, 2015 at 2:17

2 Answers 2

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.

6
  • 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. Commented Sep 7, 2015 at 8: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 "". Commented Sep 7, 2015 at 8: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. Commented Sep 7, 2015 at 13:15
  • @schily: And also I have tested with Solaris 11, its paste gave no delimiters error for paste -d "", too. Commented Sep 7, 2015 at 13:32
  • Many people believe that tools with the brand "heirloom" are from original UNIX sources, but heirloom paste is not. Commented Sep 7, 2015 at 14:07
7

The solution is:

paste -d "\0" a b

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.