This tutorial explains Linux “paste” command, options and its usage with examples.
Description :
paste writes lines consisting of the sequentially corresponding lines from each FILE, separated by tabs, to the standard output. With no FILE, or when FILE is a dash (“-“), paste reads from standard input.
Usage :
paste [OPTION]… [FILE]…
Options :
-d, –delimiters=LIST
reuse characters from LIST instead of tabs.
-s, –serial
paste one file at a time instead of in parallel.
–help
Display a help message, and exit.
–version
Display version information, and exit.
Examples :
1. Basic Example
$ cat emp-number.txt 100 200 300 400 500 $ cat emp-firstname.txt Emma Alex Madison Sanjay Nisha $ cat emp-lastname.txt Thomas Jason Randy Gupta Singh $ paste emp-number.txt emp-firstname.txt emp-lastname.txt 100 Emma Thomas 200 Alex Jason 300 Madison Randy 400 Sanjay Gupta 500 Nisha Singh
2. Join all lines into a single line with the ‘-s’ option
$ paste -s emp-number.txt 100 200 300 400 500
3. Paste command with single file is just like cat command
$ paste emp-number.txt 100 200 300 400 500
4. Join lines with a delimiter
$ paste -d - -s emp-number.txt 100-200-300-400-500
Here we have used hyphen ‘-‘ as a delimiter.
5. Merge the file into 2 columns
$ paste - - < emp-number.txt 100 200 300 400 500
6. Merge the file into 3 columns
$ paste - - -< emp-number.txt 100 200 300 400 500
7. Merge the file into multiple columns with delimiters
$ paste -d':' - - < emp-number.txt 100:200 300:400 500:
This ‘-d’ option can be used for multiple delimiters as well. For example:
$ paste -d':*' - - - < emp-number.txt 100:200*300 400:500*
8. Paste 2 files alternatively line by line using the ‘-d’ option with ‘\n’
$ paste -d'\n' emp-number.txt emp-firstname.txt 100 Emma 200 Alex 300 Madison 400 Sanjay 500 Nisha
Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.
- Check Linux Books
- Apply for Programming Internship
- Practice Programming MCQs
- Check Information Technology Books