Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

In Linux, I have the following problem with paste from (GNU coreutils) 8.13:

Trying to set another delimiter than the default (TAB) results in either just printing the first character of the defined delimiter or perfectly ignoring it.

Question: How does one define (multiple) delimiters when using paste?

Simply using, e.g. abc-123 as delimiter would be nice. With "multiple" I mean e.g. 2 TABS instead of one.


The patterns enclosing the delimiter(s) I've tried so far were

  • --delimiters="\delimiter"
  • --delimiters='\delimiter'
  • --delimiters=$"\delimiter"
  • --delimiters=$'\delimiter'

All with the same result: Only the first character is accepted or perfectly ignored. I've also tried the short version -d"\" and multiple instances &ndahs; nothing.

Also:

  • --delimiters="\\" → Error message

What works perfectly, though not what I want:

  • --delimiters="\n" → newline
  • --delimiters="\0" → nothing inbetween
  • --delimiters="\t"TAB, the default. Great.
share|improve this question

2 Answers 2

To have abc inbetween file1 and file2, you can do:

paste -d abc file1 /dev/null /dev/null file2

Or:

paste -d abc file1 - - file2 < /dev/null

If you want two tabs:

paste file1 /dev/null file2
share|improve this answer
    
"using /dev/null to create two columns in text processing" works (besides: is this common knowledge I've missed so far and if not: where did you get this information from?) –  erch Feb 18 at 19:38
1  
@Chirp.NotLuke. /dev/null acts like an empty file when reading, so you're pasting file1, and empty file, and empty file, file2 with separators being, in turn, a, b and c. Details on how -d works are in the paste man page. –  Stéphane Chazelas Feb 18 at 20:40

It's because you are giving it only two files to join, each character of delimiter string is used between each join of lines from each of the input files.

eg

file1 line1 DELIMCHAR0 file2 line1 DELIMECHAR1 file3 line1 ...
file1 line2 DELIMCHAR0 file2 line2 DELIMECHAR1 file3 line2 ...
...
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.