Bootstrap FreeKB - Linux Commands - paste (read, delimit, combine files)
Linux Commands - paste (read, delimit, combine files)

Updated:   |  Linux Commands articles

The paste command without any options is identical to the cat command. The paste command without any option can be used to view the contents of a file. 

[root@server1 ]# paste file1
Hello
world
How
are
you
today?

 

The -s (single line) option cab be used to put all of the lines into a single line.

[root@server1 ]# paste -s file1
Hello world How are you today?

 


Delimiting files

The -T (show tabs) option can be used to view the tabs in the file. The ^I is used to represent a tab.

[root@server1 ]# paste -s -T file1
Hello^Iworld^IHow^Iare^Iyou^Itoday?

 

The -d (delimitor) option can be used to delimit a file. For example, to delimit a file with a comma:

[root@server1 ]# paste -d, file1 > newfile

[root@server1 ]# cat newfile
Hello world,How are you today?

 

To delimit a file with a semicolor:

[root@server1 ]# paste -d ';'  file1 > newfile

[root@server1 ]# cat newfile
Hello;world;How;are;you;today?

 


Writing and appending files

Redirection can be used to overwrite file2 with the contents of file1.

[root@server1 ]# paste file1 > file2

 

Redirection can also be used to append the contents of file1 into file2. The \n delimiter is used so that the contents of file1 are appended to a new line in file2.

[root@server1 ]# paste -d '\n' file1 >> file2

 


Combining files

Let's say there are two files, file1 and file2, and each file has a line of text. For example, let's say file1 contains "Hello World" and file2 contains "How are you today?" The paste command can be used to place each line in the two files side by sde.

[root@server1 ]# paste file1 file2
Hello world  How are you today?

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 8c2018 in the box below so that we can be sure you are a human.