Comment by pwg
11 years ago
One use is converting columns of numbers into math strings for bc.
Example (contrived):
$ seq 10 20 | paste -s -d +
10+11+12+13+14+15+16+17+18+19+20
$ seq 10 20 | paste -s -d + | bc
165
Or converting columns of strings into regex 'or' clauses for searching (contrived example again):
$ cut -f 3 -d , something.csv | paste -s -d "|"
a|b|c|d|e|f
$ egrep "$(cut -f 3 -d , something.csv | paste -s -d "|")" another_file
... result lines appear here ...
I've used paste all my life, but I never knew you could do
to convert stdin into 2 columns (or "paste - - - -" to get 4 columns!). TIL ...
seq has the -s flag which voids the need of the paste for that command:
But I agree that the paste is very useful.
There is a faster way to get pi in bc:
(That is, 4×arctan(1)=4×π/4=π.) But your way is truly an awesome use of Unix!
ahah, so that's where R's paste() function comes from...