0

I have a file like this naming it as file1

chr1    24018319    +   a
chr1    24019249    +   b
chr1    24020403    +   c
chr1    24021281    +   d
chr1    24022398    +   e
chr1    45241272    +   f
chr1    45241812    +   g
chr1    45242446    +   h
chr1    45243461    +   I
chr1    45243801    +   j

I have some other input files as well. They look like this:

chr1    24018319    0   +
chr1    24019249    22.4309 +
chr1    24020403    64.302  +
chr1    24021281    20.9355 +
chr1    24022398    32.8987 +
chr1    45241272    1.49539 +
chr1    45241812    318.519 +
chr1    45242446    207.86  +
chr1    45243461    112.155 +
chr1    45243801    67.2927 +

These other files have same number of rows as compared to the first file, file1.

I want to add 3rd column of every such file to the first file1(since the rows are equal) and I tried paste command but it didn't work.

I want the output like this:

chr1    24018319    +   a   0
chr1    24019249    +   b   22.4309
chr1    24020403    +   c   64.302
chr1    24021281    +   d   20.9355
chr1    24022398    +   e   32.8987
chr1    45241272    +   f   1.49539
chr1    45241812    +   g   318.519
chr1    45242446    +   h   207.86
chr1    45243461    +   I   112.155
chr1    45243801    +   j   67.2927

How can I do it. I tried this

paste -d "\t" file $(cut -f 3 file2) $(cut -f 3 file3)

but this didn't work

Thanks

  • This works!! Thanks I am getting confused with command substitution and process substitution. Will read again – user3138373 Jul 9 '15 at 3:25
0

The command below generates the output you request in your example to some extent, although doesnt preserve the spaces.

$ join -j 2 -o 1.1 1.2 1.3 1.4 2.3 file1 file2
chr1 24018319 + a 0
chr1 24019249 + b 22.4309
chr1 24020403 + c 64.302
chr1 24021281 + d 20.9355
chr1 24022398 + e 32.8987
chr1 45241272 + f 1.49539
chr1 45241812 + g 318.519
chr1 45242446 + h 207.86
chr1 45243461 + I 112.155
chr1 45243801 + j 67.2927
$ 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.