Issue with paste command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Issue with paste command
# 1  
Old 11-20-2014
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
Code:
TH
THI
THIS I

File_2
Code:
IS IS 
S IS RE
S

File_3
Code:
RECORD 1
CORD 2
IS RECORD 3

Output should be
Code:
THIS IS RECORD 1
THIS IS RECORD 2
THIS IS RECORD 3

Initially I used the command -
Code:
paste File_1 File_2 File_3 > outfile

This added spaces and tabs.

Then I changed the command to
Code:
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!!!

Last edited by rbatte1; 11-24-2014 at 10:57 AM.. Reason: Spelling
# 2  
Old 11-20-2014
What OS and shell are you using?

When I try your command:
Code:
paste -d '\0' File_1 File_2 File_3 > outfile

or:
Code:
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:
Code:
THIS ISIS RECORD 3

instead of:
Code:
THIS IS RECORD 3

And, with the three input files you supplied, this seems to be correct to me.
# 3  
Old 11-20-2014
Shouldn't you remove the ASCII zeroes from the result file?
# 4  
Old 11-20-2014
Quote:
Originally Posted by RudiC
Shouldn't you remove the ASCII zeroes from the result file?
No ASCII zeroes are added by the command:
Code:
paste -d '\0' File_1 File_2 File_3 > outfile

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

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:
Code:
paste -d '' File_1 File_2 File_3 > outfile

produces the diagnostic message:
Code:
paste: no delimiters specified

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

Last edited by Don Cragun; 11-20-2014 at 03:04 PM.. Reason: Add note re: why not just use -d ''
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Paste command formatting

Hi, I was trying to concatenate some files using paste command along with some formatting but getting stuck. The problem is: cat 1.txt A cat 2.txt B C cat3.txt D E cat 4.txt G H (5 Replies)
Discussion started by: abhi1988sri
5 Replies

2. Shell Programming and Scripting

Issue with cut and paste

let i have A file and B file A has contains 4 fields as below ---------------- f1 f2 f3 f4 B file consists of 5 fields as below -------------------- f5 f6 f7 f8 f9 need to display as below output: f5 f1 f3 f8 f9 (2 Replies)
Discussion started by: ANSHUMAN1983
2 Replies

3. UNIX for Dummies Questions & Answers

paste command without spacing?

I'm trying to combine text files without a space. So if i use the paste command paste file1 file2 file3 > file4 the new file created has spacing between the contents of the once individual files. Is there some trick I can do with a delimiter that removes the spaces.. like paste -d'' or... (1 Reply)
Discussion started by: steveinthebox
1 Replies

4. Shell Programming and Scripting

Can't paste in command line.

Hello. I've made a simple script which asks the user to input a hash and then runs a command that replaces the variable $hash with what the user inserted. The ting is that when the programm asks for input I can't paste anything there..! any clues?? :wall: (8 Replies)
Discussion started by: louboulos
8 Replies

5. UNIX for Dummies Questions & Answers

Need help with using cut and paste command

I have a file which contains 3 fields separated by tabs example andrew kid baker I need to swap kid and baker using cut and paste commands how is this to be done? Thanks (1 Reply)
Discussion started by: drew211
1 Replies

6. UNIX for Dummies Questions & Answers

paste command

input1 15 150 input2 x 10 100 input3 y 20 200 z 34 44 cmd paste -d "\t" input1 input2 input3 >>output output (1 Reply)
Discussion started by: repinementer
1 Replies

7. Shell Programming and Scripting

command paste with variables

Hi. I have an interesting problem and i couldn't find out the solution. I have two variables in which there are a lot of lines finished by \n. I would like to concatenate this two variables into one in this format: var1var2 var1var2 . . . I could do this simply by command paste but it works... (32 Replies)
Discussion started by: samos
32 Replies

8. Shell Programming and Scripting

Paste command issue

Problem with Paste command :) Hi All, i need small suggestion in my below script... i have output in .txt format like below file1.txt 01111111 02222222 03333333 file2.txt 230125 000012 000002 now i want to merge both the file in xls or csv formate now i am using the below... (2 Replies)
Discussion started by: Shahul
2 Replies

9. UNIX for Dummies Questions & Answers

Question on Paste command

Hello everyone, This is Rameshreddy. I like this forum and its nice to share everyone's experience here and one can learn a lot from here. Appreciate the moderators especially. Coming to my question i have 2 files and i want to paste them with specific number of tabs as delimiters... (4 Replies)
Discussion started by: mudhireddy
4 Replies

10. UNIX for Advanced & Expert Users

paste command

I wonder if any body can help me with a command i am struggling with. I have a file with around 400 lines in, in a program i have it pulls out each line at a time so that data from the line can be cross referenced with another file. If it finds a match it pulls out a ocde from the second file, this... (5 Replies)
Discussion started by: mariner
5 Replies
Login or Register to Ask a Question