Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making paste command read from standard input

Tags:

linux

shell

paste

$paste num let
1    a
2    b
3    c
4    d

So when I do

$ cat num | paste - - 
1    2
3    4

My question is why doesn't "cat num | paste - -" generate the output as:

1     1
2     2
3     3
4     4
like image 986
Ameyj Avatar asked Oct 21 '14 06:10

Ameyj


1 Answers

Clearly, paste reads a line from the first 'file' (which is standard input), and then a line from the second 'file' (which is also standard input) and pastes them to create the first line of output. Then it repeats.

The POSIX specification for paste covers the point explicitly:

If '-' is specified for one or more of the files, the standard input shall be used; the standard input shall be read one line at a time, circularly, for each instance of '-'.

like image 68
Jonathan Leffler Avatar answered Sep 25 '22 23:09

Jonathan Leffler