Reputation: 2559
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
Upvotes: 3
Views: 3491
Reputation: 784998
An awk
command can also do the job with OFS=',,'
:
awk -v OFS=',,' 'NR==FNR{a[FNR]=$0; next} {print a[FNR], $0}' file1 file2
Upvotes: 2
Reputation: 780798
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.
Upvotes: 4
Reputation: 189327
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.)
Upvotes: 8