EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Software Development Software Development Tutorials Unix Tutorial Paste Command in Unix
 

Paste Command in Unix

Updated May 31, 2023

Paste Command in Unix

 

 

Introduction to Paste Command in Unix

Paste Command in Unix is among the most common and useful commands in Unix or Linux Shell Scripting. The main use of the paste command is to join the files horizontally by separating the lines from each file with a tab as a delimiter to get the required output. Paste command can be used to merge a single file or set of files aGenerally, the paste command is used both for single file handling and multiple file handling.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Syntax:

The basic syntax of the paste command in Unix Shell Scripting is given below:

paste [option].. [files]..

How does Paste Command work in Unix?

The main use of the paste command is to join the files horizontally by separating the lines from each file with a tab as a delimiter to get the required output.

Options that are available in paste commands are:

  • -d, delimiter: Specifies the delimiter mentioned in the input parameter to display the output in a specified manner.
  • – – help: This option helps to display the help message and options available in the paste command.
  • – – version: Displays the version of the paste command that is running in your system and exit.
  • – s, -serial: Helps display the file’s contents in a horizontal format.

Examples of Paste Command in Unix

Given below are the examples of Paste Command in Unix:

a. Paste Command for Single File Handling.

Let us consider a file ‘testing.txt’ that has the below contents. We can list the contents in the file by using the ‘cat’ command as shown below:

Code:

cat testing.txt

Output:

Paste Command in Unix 1

Paste command with a single file can be similar to a cat command in Unix. You can see below that the paste command works functionally like the cat command in the example below.

Code:

paste testing.txt

Output:

Paste Command in Unix 2

Example #1: Option -s

Option’ s’ joins the contents in lines to a horizontal format. As no delimiter is specified, ‘tab’ is taken as a delimiter for the column separator.

Syntax:

paste -s  file_name.txt

Code:

paste -s testing.txt

Output:

Paste Command in Unix 3

Example #2: Option -d

Paste command when used with option ‘d’, is used to mention the delimiter. When it is used with a combination of -d and -s, then the lines in the files are merged into one single line with the delimiter specified.

Syntax:

paste -d, -s file_name.txt

Code:

paste -d, -s testing.txt

Output:

Paste Command in Unix 5

Example #3: Merge the contents in a column

The option ‘-‘ reads a line from the input file given. The number of ‘-‘s passed in the input will give the number of lines to be split side by side.

Syntax:

paste - - < file_name.txt

Code:

paste - - < testing.txt

Output:

Paste Command in Unix 6

Example #4: Merge the contents with a delimiter

We can split the lines into columns with the specified delimiter by specifying the delimiter.

Syntax:

paste -d'-' - - < file_name.txt

Code:

paste -d ' - ' - - < testing.txt

Output:

Merge the contents with a delimiter

Example #5: Merge the data into different delimiters

We can also merge the lines in the file with different delimiters by passing two different delimiters in the input parameters.

Syntax:

paste -d',:' - - - < file_name.txt

Code:

paste -d ' , : ' - - - < testing.txt

Output:

Merge the data into different delimiters

b. Paste Command Options for Multiple File Handling.

Let us consider a file ‘testing2.txt’ with the following lines:

Code:

cat testing2.txt

Output:

Paste Command in Unix 9

Example #1: Option paste

When we try to paste both files, the paste command merges both files mentioned in the input side by side.

Syntax:

paste file1.txt file2.txt

Code:

paste testing.txt testing2.txt

Output:

Option

Example #2: Option -d

Option ‘d’ helps to merge two files side by side with a delimiter specified in the input parameters.

Syntax:

paste -d, file1.txt file2.txt

Code:

paste -d, testing.txt testing2.txt

Output:

Paste Command in Unix 12

Example #3: Option ‘\n’

The paste command in Unix actively allows reading lines from both files alternately. Each line is displayed alternatively one by one and is given as an output.

Syntax:

paste -d'\n' file1.txt file2.txt

Code:

paste -d ' \n ' testing.txt testing2.txt

Output:

Paste Command in Unix 13

Example #4: Option –version

This option helps us know the version of the paste command used in our system.

Syntax:

paste –version

Code:

paste - - version

Output:

Option --version

Example #5: Option –help

To display the options that can be used with the paste command in Unix Shell Scripting, actively use the ‘–help’ option.

Syntax:

paste –help

Code:

paste - -help

Output:

Option –help

Conclusion

From the above article, we are now clear on using the paste command in Unix Shell Scripting with different options as per the required output. The paste command actively merges one or more lines in the input files. As the article above demonstrates, it can handle single or multiple files in the paste options.

Recommended Articles

We hope that this EDUCBA information on “Paste Command in Unix” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

  1. For Loop in Unix
  2. Crontab in Unix
  3. VI Editor in Unix
  4. Uses of Unix

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

🚀 Limited Time Offer! - ENROLL NOW