This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Merging File

I have two files like file1.dat and file2.dat I would like to combine the file without changing the format of file1 and file2. file1(2space)file2.

for example File1:

    1 2 3  4 5             
    6 7 8  8 9

File2:

      8 6 4258
      8 5 9927

The result i want is

                         1 2 3 4 5(2space)8 6 4258
                         6 7 8 8 9(2space)8 5 9927

I have tried with paste -d ' ' file1 and file2 but got only one space between the file. I have 5 column and thousand of rows in files.

thank you in advance

PRT

This is a simple programming problem and not bioinformatics related (remains so, even if the files contain some biological data). Closing because solved elsewhere. A possible solution based on join is (like a relational database join, using content of certain columns) presented here: http://stackoverflow.com/questions/15839546/merging-two-files-based-on-two-columns

or here, if it is just about joining row by row: http://unix.stackexchange.com/questions/16443/combine-text-files-column-wise

1 answer

this is probably not the best solution bc it involves 2 steps but a quick one if you are in a hurry:

paste -d '\t' file1 file2 >file3

this will place a tab between the two files and save in file3 Then you can substitute the tab for two spaces in file3:

sed 's/\t/ /g' file3

(with two spaces between the / /)

there is definitely a more direct way to do this

good luck!

a caveat: this will replace ALL tabs in your file. You want to make sure there aren't any other tabs.

Log in to answer this question.