paste (Unix)

From Wikipedia, the free encyclopedia
(Redirected from Paste (Unix program))
Jump to navigation Jump to search
paste
Original authorsAT&T Bell Labs
DeveloperGNU Project
Initial release1973 (as part of Version 4 Unix)
Repository
  • {{URL|example.com|optional display text}}Lua error in Module:EditAtWikidata at line 29: attempt to index field 'wikibase' (a nil value).
Written inC
Engine
    Lua error in Module:EditAtWikidata at line 29: attempt to index field 'wikibase' (a nil value).
    Operating systemUnix, Unix-like (Linux, macOS)
    PlatformPOSIX-compliant systems, Cross-platform
    TypeCommand-line utility
    Licensecoreutils: GPL v3+
    WebsiteGNU manual

    paste is a shell command that joins files horizontally (parallel merging) by writing to standard output lines consisting of the sequentially corresponding lines of each input file, separated by tabs.

    The command reads each specified input file line-by-line. For each set of input lines, the command outputs a line formatted as the concatenation of the input files' lines separated by a tab character. If the content of a file runs out, the command will use an empty string for the file. As such, the number of output lines will equal the number of lines of the file with the most lines. Some implementations support using a fixed string (such as "NA") when a files content is exhausted before the others.

    A sequence of empty records at the bottom of a column of the output stream may or may not have been present in the input file corresponding to that column as explicit empty records, unless you know the input file supplied all rows explicitly (e.g. in the canonical case where all input files all do indeed have the same number of lines).

    The command accepts the following options:

    -d|--delimiters delimiters, specifies a list of delimiters to use instead of tabs for separating consecutive values on a single line. Each delimiter is used in turn, and when the list has been exhausted, paste begins again at the first delimiter.
    -s|--serial, select to append in serial rather than in parallel; that is, horizontal rather than vertical.

    The command was developed for Unix at Bell Labs by Gottfried W. R. Luderer.[1][2] The implementation bundled in GNU coreutils was written by David M. Ihnat and David MacKenzie.[3] The command is available for Windows via UnxUtils.[4]

    Examples

    [edit | edit source]

    For the following examples, names.txt is a plain-text file that contains:

    Mark Smith
    Bobby Brown
    Sue Miller
    Jenny Igotit
    

    numbers.txt is another plain-text file that contains:

    555-1234
    555-9876
    555-6743
    867-5309
    

    The following command joins the two files.

    $ paste names.txt numbers.txt
    Mark Smith	555-1234
    Bobby Brown	555-9876
    Sue Miller	555-6743
    Jenny Igotit	867-5309
    

    When invoked with the --serial option (-s on BSD or older systems), the files are joined horizontally:

    $ paste --serial names.txt numbers.txt
    Mark Smith	Bobby Brown	Sue Miller	Jenny Igotit
    555-1234	555-9876	555-6734	867-5309
    

    The use of the --delimiters option (-d on BSD or older systems) is illustrated in the following example:

    $ paste --delimiters . names.txt numbers.txt
    Mark Smith.555-1234
    Bobby Brown.555-9876
    Sue Miller.555-6743
    Jenny Igotit.867-5309
    

    Sum the numbers from 1 to 100:

    $ seq 1 100 | paste -d + -s | bc
    5050
    

    See also

    [edit | edit source]

    References

    [edit | edit source]
    1. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    2. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    3. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    4. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    [edit | edit source]
    • Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).