Pages

vendredi 25 mai 2012

paste: concatenate columns to form a new file

If file1:
0.0066
0.0357
0.0475
0.0609
0.0370
0.0443

file2:
0.0181
0.0176
0.0155
0.0152
0.0131
0.0137

Then use the linux command "paste file1 file2 ", we can concatenate two columns as follows :

0.0066 0.0181
0.0357 0.0176
0.0475 0.0155
0.0609 0.0152
0.0370 0.0131
0.0443 0.0137

by default the delimiter is Tab. If we want to define our own delimiter, we can :

paste -d " " file1 file2 

This will use one-space as the delimiter between the two.


If the two files have multiple lines, it seems to me that paste has difficulty to merge them correctly. In a case I have two files and each have 3 columns. Finally what it works well is:

pr  -t  -m   file1  file2

Aucun commentaire:

Enregistrer un commentaire