2

I have a file (1kG_MDS5.bim) like this:

1   rs58108140  0   10583   A   G
1   1:11508[b37]A,G 0   11508   A   G
1   1:15820[b37]G,T 0   15820   T   G
1   1:16257[b37]C,G 0   16257   C   G
1   1:16378[b37]C,T 0   16378   T   C

I would like to remove all occurrences of [b37] in the 2nd column and also replace comma with column so that the FINAL result looks like this:

1   rs58108140  0   10583   A   G
1   1:11508:A:G 0   11508   A   G
1   1:15820:G:T 0   15820   T   G
1   1:16257:C:G 0   16257   C   G
1   1:16378:C:T 0   16378   T   C

I tried to partially solve this (by just removing [b37]) by running:

sed -i -E 's/([b37])/:/g' 1kG_MDS5.bim

but I got this:

1   rs58108140  0   1058:   A   G
1   1:11508[:::]A,G 0   11508   A   G
1   1:15820[:::]G,T 0   15820   T   G
1   1:1625:[:::]C,G 0   1625:   C   G

Can you please advise me on how to get the final results where the lines would look like shown above. It doesn't need to be sed solution (awk would be great) Also this file contains about 6 million lines.

1 Answer 1

1

You can try this:

sed 's/\[b37\]\(.\),/:\1:/' 1kG_MDS5.bim

Output:

1   rs58108140  0   10583   A   G
1   1:11508:A:G 0   11508   A   G
1   1:15820:G:T 0   15820   T   G
1   1:16257:C:G 0   16257   C   G
1   1:16378:C:T 0   16378   T   C

The problem in your pattern is that the brackets are not escaped, so sed tries to replace the occurrences of b, 3 and 7, not the string "[b37]".

6
  • Do you know how to make this command so that I get: 1 1:11508:A:G 0 11508 A G
    – anamaria
    Mar 24, 2020 at 18:44
  • @anamaria post it in the question :) Mar 24, 2020 at 18:45
  • Thanks! I didn't know how to get that part but on the beginning of the post I have how the final result should look like.
    – anamaria
    Mar 24, 2020 at 18:47
  • O sorry, I'm on it Mar 24, 2020 at 18:47
  • I think now I got it. Mar 24, 2020 at 18:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .