• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

paste Command Examples in Linux

by admin

The paste command is used to merge lines from text files horizontally. Each line of an initial file is a row in the first column; using paste, you specify a second file, and every line of the second file becomes a row in a new, second column. By default, the paste command uses a tab space delimiter to separate each column. You can use the -d option to specify a different delimiter.

For example, you have a file named cities:

# cat file1
Mumbai
Pune
Delhi
Chennai

You also have a second file named countries:

# cat file2
India
China
UK
USA

The output of paste -d , cities countries is as follows:

# paste file1 file2
Mumbai,India
Pune,China
Delhi,UK
Chennai,USA

The commonly used delimiters with the -d option are space, Tab, |, :, and comma. An enhanced version of the paste command is join, which can work on files that have similar columns.

paste Command Examples

1. Join all the lines into a single line, using TAB as delimiter:

# paste -s file

2. Join all the lines into a single line, using the specified delimiter:

# paste -s -d delimiter file

3. Merge two files side by side, each in its column, using TAB as delimiter:

# paste file1 file2

4. Merge two files side by side, each in its column, using the specified delimiter:

# paste -d delimiter file1 file2

5. Merge two files, with lines added alternatively:

# paste -d '\n' file1 file2

Filed Under: Linux

Some more articles you might also be interested in …

  1. brctl Command Examples in Linux
  2. sed: command not found
  3. Windows Active Directory Account Shows Inconsistent UID/GID In Different Linux SSSD Clients (CentOS/RHEL)
  4. systemctl: command not found
  5. 520000 – FAQ: Valuated special stock
  6. Cannot Increase “nproc” Value More Than 1024 in CentOS/RHEL 6
  7. NFSv4 mountpoint shows incorrect ownerships as nobody:nobody in CentOS/RHEL
  8. chpasswd Command Examples in Linux
  9. CentOS / RHEL : How to find free space in a Volume Group in LVM
  10. pkginfo: command not found

You May Also Like

Primary Sidebar

Recent Posts

  • powertop Command Examples in Linux
  • powertop: command not found
  • powerstat: command not found
  • powerstat Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright