Paste Command in Linux with Examples

Tamizh Tech Tutorial

Paste Command in Linux 
(Linux Commands)

Linux for Beginners

Paste Command in Linux (5 Examples)

This tutorial provides 5 practical examples of paste command in linux / unix OS.

Paste Command 

  • This command is mainly used to merge the file contents horizontally 

  • This command is also used to display the single file contents.

Operations

  • Merging Files Horizontally

  • Merging Files Horizontally with delimiter option

  • Merging Files Sequentially

  • Displaying File Contents using Paste

  • Reading and Displaying Data in Paste Command

1. Merging Files Horizontally

  • Be default, the paste command is used to merge the two or more number of files horizontally (parallelly) with tab delimiter

  • Here, lines of the files are merged horizontally

Syntax

paste file1 file2 … file n

Example

  • Here files like f1.txt, f2.txt and f3.txt are merged horizontally with tab delimiter by default using paste command.

2. Merging Files Horizontally with delimiter option

  • Be default, files are merged horizontally (parallelly) with tab delimiter

  • If you want to change the tab delimiter, then you have to use the special option -d with new delimiter like space, |, etc

  • The delimiter should be given inside the single quote or double quotes. 

Syntax

paste -d “ ”file1 file2 … file n

Example

3. Merging Files Sequentially

  • By default, files are merged horizontally (parallelly) 

  • If you want to merge files sequentially (one by one) then we need to use the special option -s (serial)

Note

  • In this option, the whole file contents will be read line by line and merge them into single line where each line is separated by tab 

  • Finally all lines of files are merged sequentially separated by newline

Syntax

paste -s “ ”file1 file2 … file n

Example

4. Displaying File Contents using Paste

  • Like cat command, paste command will also display the file contents

  • If paste command will take only one argument as file input then will display the file contents instead of merging.

Syntax

paste filename

Example

5. Reading and Displaying Data in Paste Command

  • If paste command is used without any option, then it will read the data from standard input and display them immediately to standard output until the stop using ctrl+c or ctrl+z.

Syntax

paste 

Example




Comments

Popular posts from this blog

Vivo V30 Pro 5G

Xiaomi 14 - Features, Price

Oppo F25 Pro 5G Review - Features, Price