Question: (Closed) Merging File
0
gravatar for prt-hntr
4.5 years ago by
prt-hntr10
New Delhi
prt-hntr10 wrote:

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

• 1.2k views
ADD COMMENTlink modified 4.5 years ago by Dalia30 • written 4.5 years ago by prt-hntr10
2

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

ADD REPLYlink modified 4.5 years ago • written 4.5 years ago by Michael Dondrup44k
1
gravatar for Dalia
4.5 years ago by
Dalia30
Rochester, NY
Dalia30 wrote:

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.

ADD COMMENTlink modified 4.5 years ago • written 4.5 years ago by Dalia30
Please log in to add an answer.
The thread is closed. No new answers may be added.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1243 users visited in the last hour