Issue with paste command

Hi,

I am facing issue with paste command. It is adding spaces or tab in between.

I have say 3 files with below data

File_1

TH
THI
THIS I

File_2

IS IS 
S IS RE
S 

File_3

RECORD 1
CORD 2
IS RECORD 3

Output should be

THIS IS RECORD 1
THIS IS RECORD 2
THIS IS RECORD 3

Initially I used the command -

paste File_1 File_2 File_3 > outfile

This added spaces and tabs.

Then I changed the command to

paste -d '\0' File_1 File_2 File_3 > outfile

This is giving some weird result where data from file 1 is missing also a special character / is coming in between.

Please help in resolving this issue.

Thanks in advance!!!

What OS and shell are you using?

When I try your command:

paste -d '\0' File_1 File_2 File_3 > outfile

or:

paste -d '\0\0\n' File_1 File_2 File_3 > outfile

I get the output you said you wanted, except that the 3rd line of the output is:

THIS ISIS RECORD 3

instead of:

THIS IS RECORD 3

And, with the three input files you supplied, this seems to be correct to me.

Shouldn't you remove the ASCII zeroes from the result file?

No ASCII zeroes are added by the command:

paste -d '\0' File_1 File_2 File_3 > outfile

From the current description of the paste -d option in the standards:

...

When the s option is not specified:
� The <newline> characters in the file specified by the last file operand shall
not be modified.
� The delimiter shall be reset to the first element of list each time a line is
processed from each file.
If a <backslash> character appears in list, it and the character following it shall be
used to represent the following delimiter characters:
\n	<newline>.
\t	<tab>.
\\	<backslash> character.
\0	Empty string (not a null character). If �\0� is immediately followed by the
	character �x�, the character �X�, or any character defined by the LC_CTYPE
	digit keyword (see XBD Chapter 7, on page 135), the results are unspecified.

If any other characters follow the <backslash>, the results are unspecified.

Note also that, at least on some implementations, the seemingly obvious:

paste -d '' File_1 File_2 File_3 > outfile

produces the diagnostic message:

paste: no delimiters specified

and an exit status of 1. (This result is copied from OS X Version 10.10.1.)

1 Like