UNIX paste command

Paste Command in Unix / Linux

paste_command_in_unix_/_linux

UNIX Paste Command

Paste command is one of the useful commands in UNIX or LINUX operating system.The paste command merges the lines from multiple files. The paste command sequentially writes the corresponding lines from each file separated by a TAB delimiter on the UNIX terminal.

The syntax of the paste command is

paste [options] files-list

The options of paste command are:

-d : Specify of a list of delimiters.
-s : Paste one file at a time instead of in parallel.
--version : version information
--help : Help about the paste command.

Paste Command Examples:

Creating below three files

> cat file1
Unix
Linux
Windows

> cat file2
Dedicated server
Virtual server

> cat file3
Hosting
Machine
Operating system

  1. Merging files in parallel
  2. By default, the paste command merges the files in parallel. The paste command writes corresponding lines from the files as a tab delimited on the terminal.

    > paste file1 file2
    Unix    Dedicated server
    Linux   Virtual server
    Windows
    
    > paste file2 file1
    Dedicated server  Unix
    Virtual server    Linux
                      Windows
    

  3. Specifying the delimiter
  4. Paste command uses the tab delimiter by default for merging the files. You can change the delimiter to any other character by using the -d option.

    > paste -d"|" file1 file2
    Unix|Dedicated server
    Linux|Virtual server
    Windows|
    

    In the above example, pipe delimiter is specified.

  5. Merging files in sequentially.
  6. You can merge the files in sequentially using the -s option. The paste command reads each file in sequentially. It reads all the lines from a single file and merges all these lines into a single line.

    > paste -s file1 file2
    Unix    Linux   Windows
    Dedicated server        Virtual server
    

    The following example shows how to specify a delimiter for sequential merging of files:

    > paste -s -d"," file1 file2
    Unix,Linux,Windows
    Dedicated server,Virtual server
    

  7. Specifying multiple delimiters.
  8. Multiple delimiters come in handy when you want to merge more than two files with different delimiters. For example I want to merge file1, file2 with pipe delimiter and file2, file3 with comma delimiter. In this case multiple delimiters will be helpful.

    > paste -d"|," file1 file2 file3
    Unix|Dedicated server,Hosting
    Linux|Virtual server,Machine
    Windows|,Operating system
    

  9. Combining N consecutive lines
  10. The paste command can also be used to merge N consecutive lines from a file into a single line. The following example merges 2 consecutive lines into a single line

    > cat file1 | paste - -
    Unix    Linux
    Windows
    


If you like dEexams.com and would like to contribute, you can also write your article here or mail your article to admin@deexams.com . See your article appearing on the dEexams.com main page and help others to learn.


Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.


Python if , elif and else

Python Conditions and If statements

  • 0
Python for beginners

Learning Python Part 1

  • 3
Struct Alignment and Padding

Struct Alignment and Padding in C++ And C

  • 0
Friend function

Friend function C++

  • 0
Pointers

C++ Pointers

  • 0
Structures

C++ Structures

  • 0
Types of Inheritance in C++

Inheritance and access specifiers C++

  • 0
Java date pattern

Java Date Pattern Syntax

  • 0
Java Date and Calendar

Java Date formats

  • 0
JAVA Data Type

Data types in Java

  • 0
Java unreachable code

Unreachable Code Error in Java

  • 0

Post Comment

Comments(0)

WEB TECHNOLOGY

Articles

×

Forgot Password

Please enter your email address below and we will send you information to change your password.