Paste Command/Utility in Linux Shell


There is a ‘paste‘ command which is less known and used on Linux shell environment. The ‘paste‘ command doesn’t work as it sounds (copy + paste, cut + paste). Instead, it takes two paramters (file names) and put them together (output to console by default) column by column.

Here is the manual of paste if you type in manual paste on the shell.

linux-paste-manual Paste Command/Utility in Linux Shell beginner linux

Suppose, we have two files, which are:

pi@raspberrypi:~$ cat A
1
2
3
4
5
6
7
8
pi@raspberrypi:~$ cat B
A
B
C
D
E
F
G
H

If we run paste A B, we ‘ll get:

pi@raspberrypi:~$ paste A B
1       A
2       B
3       C
4       D
5       E
6       F
7       G
8       H
pi@raspberrypi:~$ 

So the two files are concatenated column by column and this is separated by default delimiter, which is TAB.

We can specify the delimiter by using -d switch, something like this paste -d, A B:

pi@raspberrypi:~$ paste -d, A B
1,A
2,B
3,C
4,D
5,E
6,F
7,G
8,H

We can also paste the files in serial instead of parallel, using the -s switch. e.g. paste -s A B:

pi@raspberrypi:~$ paste -s A B
1       2       3       4       5       6       7       8
A       B       C       D       E       F       G       H

Combined both, e.g. paste -d, -s A B

pi@raspberrypi:~$ paste -d, -s A B
1,2,3,4,5,6,7,8
A,B,C,D,E,F,G,H

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
322 words
Last Post: Send Keystrokes to the Active Window using SendKeys (WSH)
Next Post: Useful Utility on Windows Shell to Copy Output Content to Clipboard

The Permanent URL is: Paste Command/Utility in Linux Shell

Leave a Reply