2014/09/09: cut and paste

Most people know how to extract a column from a text file; cut(1) is the specialised tool for this, but you can always use awk(1).

However, it seems that the dual, putting different files into separate columns of a combined file seems to be a lot less known. The name is quite canonical: it is called paste(1). By default, the columns are separated by the tab character (but other delimiters can be chosen with the -d option), so together with expand(1) you can have the columns visible as ASCII-art.


cat foo
foo
foooo
/tmp>cat bar
bar
baz
bar bar
/tmp>paste foo bar | xxd
0000000: 666f 6f09 6261 720a 666f 6f6f 6f09 6261  foo.bar.foooo.ba
0000010: 7a0a 0962 6172 2062 6172 0a              z..bar bar.
/tmp>paste foo bar | expand -40
foo                                     bar
foooo                                   baz
                                        bar bar
/tmp>