The paste
command is used to combine lines from multiple files into a single stream,
then pass it to stdout.
The call signature is
paste {options} {paths}
The paste
command combines the files by line index, so the ordering of the contents of
each file are important. Moreover, this command will continue reading input until the
longest input file has been exhausted. If any files are exhausted prior to then, they
will produce empty strings.
It is easiest to understand how paste
operates with a few simple examples.
Suppose we have two files, names.txt and codes.txt, each containing the following information:
Now, suppose we want to combine them into a single comma-delimited stream. The default
delimiter is the Tab-character, so we first use the -d
option to set it. Next, we
specify the input file names in the order they should be read. The final command and
output are:
To reverse the order of the output fields, simply reverse the order that the input files are specified: