paste Command in Linux

Learn via video courses
Topics Covered

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Overview

The 'paste' command in Linux is a powerful yet often overlooked tool used for manipulating and processing text data. This command merges the lines of files in a sequential manner, providing an efficient way to combine and reformat data quickly. It's primarily used in scripting and data manipulation tasks, proving to be a handy tool for system administrators and programmers alike.

Syntax of paste Command in Linux

The basic syntax of the paste command in Linux is as follows:

Where:

  • OPTION: These are the flags or parameters that modify the behavior of the paste command.
  • FILE: This refers to the file(s) whose content will be manipulated by the paste command. Multiple files can be specified.
Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course

Options in paste Command in Linux

  1. -d, --delimiters=LIST: Use characters from LIST instead of TAB as delimiter. With no FILE, or when FILE is -, read standard input.

    For example -

    Output:

    The paste command uses space instead of tab as a delimiter to join the lines from file1.txt and file2.txt.

  2. -s, --serial: Paste one file at a time instead of in parallel.

    For example -

    Output:

    The -s option makes the paste command process files serially. Each file's contents are pasted on a single line, separated by tabs.

  3. --help: Display a help message and exit.

    For example -

    Output:

    This command prints a detailed help message for the paste command, including all available options and their explanations.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Example Usages

  • Basic usage of paste command with two files.:

    Output:

    Explanation: The paste command is joining the lines from file1.txt and file2.txt, separated by tabs.

  • Using paste command to combine lines from a single file.:

    Output:

    Explanation: The '-' reads from standard input. Here, paste reads two lines from file1.txt and outputs them on a single line, separated by a tab.

Tips

  • The paste command treats '-' (dash) as standard input. If no FILE, or when FILE is -, it reads from the standard input.

  • While using the -d option, multiple delimiters can be specified and they will be used in sequence.

  • When the files to be pasted do not contain the same number of lines, paste fills the missing values with tabs.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Advanced Use Cases of paste Command in Linux

  • Creating a CSV file using paste command.:

    Output:

    Explanation: The paste command uses comma as a delimiter to join the lines from file1.txt and file2.txt and outputs it to a .csv file.

  • Using paste command with process substitution.:

    Output:

    Explanation: This command uses process substitution to generate input for the paste command, which then joins the lines as expected.

  • Using paste command to transpose rows to columns.:

    Output:

    Explanation: The paste command with -s and -d options can transpose rows to columns. This command converts each line from file1.txt into a tab-separated value on a single line.

Conclusion

  • The paste command in Linux is a versatile tool for manipulating and merging text files.

  • With a variety of options, paste command offers a high degree of flexibility in text processing tasks.

  • From creating CSV files to transposing data, the potential applications of paste command are extensive in the field of data manipulation.