Search notes:

Shell command: paste

Without command line options

paste file-1 file-2 … file-n
Without command line options, paste will read one line from each file and write each line, without new line, but separated by a tabulator. It will do that until the all lines are read.
So, if file_one contains
foo
bar
baz
and file_two contains
one
two
three
then paste file_one file_two will print
foo       one
bar       two
baz       three
This behavior is somewhat similar to that obtained with the shell command pr -mt … or with positional joins in DuckDB.

-d delimiter

-d specifies one or more delimiters (instead of the default tabulator) with which the lines will be pasted.
paste -d, file_one file_two will print
foo,one
bar,two
baz,three

-s don't read files in parallel

-s can be used to create a pivot from a file.
If some.txt contains
foo
10.3
18.9
17.1
bar
7.8
12.7
15.6
baz
11.4
15.1
16.4
then paste -d "\t\t\t\n" some.txt will print
foo	10.3	18.9	17.1
bar	7.8	12.7	15.6
baz	11.4	15.1	16.4
Note how each delimiter is used in sequence and then «recycled».

Examples

seq 10 | paste -sd+ | bc
calculates the sum of the first 10 integers: it will print 55.

See also

Shell commands
The R function paste and the Python function zip.

Links

https://github.com/ReneNyffenegger/shell-commands/tree/master/paste

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Linux/sh...', 1758844126, '216.73.216.5', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Linux/shell/commands/paste(114): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78