Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paste files with extended delimiter in bash

Tags:

bash

paste

Good day people!

Today, I was wondering how to paste several files with this delimiter: ,,.

When I use like:

paste -d',,' ...

The output only introduce one ,

I need double comma for better handling csv files, Thanks in advance for any clue

like image 808
Another.Chemist Avatar asked Jan 30 '26 06:01

Another.Chemist


2 Answers

If you can identify a character which is not used in the file, you can do this in two steps.

paste -d '~' file1 file2 | sed 's/~/,,/'

Obviously, if the tilde already exists in your data, use a different delimiter. A control character could be a fairly safe bet, at the expense of being slightly pesky to manipulate. (In Bash, you can use e.g. $'\001' to produce a ctrl-A, etc.)

like image 50
tripleee Avatar answered Jan 31 '26 22:01

tripleee


This works:

paste -d, file1 /dev/null file2

The documentation says:

If end-of-file is reached on an input file while other input files still contain data, the file is treated as if it were an endless source of empty lines.

Since /dev/null returns EOF immediately, it will simply be an endless source of blank lines. These will be inserted as an empty field between the contents of the two real files.

like image 22
Barmar Avatar answered Jan 31 '26 20:01

Barmar