I have a tab delimited file with following format (multiple columns):

1   22  .   C   A   .   PASS    aa;bb;cc    ee:ff:rr:dd xx:vv:yy:zz
1   34  .   G   T   .   PASS    aa;bb;cc    ee:ff:rr:dd xx:vv:yy:zz
1   56  .   C   G   .   PASS    aa;bb;cc    ee:ff:rr:dd xx:vv:yy:zz

desired output:

1   22  C   A   .   zz  vv/yy   cc
1   34  G   T   .   zz  vv/yy   cc
1   56  C   G   .   zz  vv/yy   cc

I tried following for partially achieving the above task, but it doesn't seem to be working:

Can anyone suggest a solution with awk or sed?

  • Where does the . (period) come from in your output? It's not the 5th "entry" of column 10; should it always be a period, or is it one of the columns? You might spell out how columns 8 and 10 are split up (by colons and semicolons I assume?). Also, how did you get 0.40 = 51 (3rd entry of 10) / 31 (4th entry of 10)? – Jeff Schaller Nov 2 '17 at 1:00
  • Your sample output does not match your specification. – fpmurphy Nov 2 '17 at 1:09
  • If there’s a header, you should include it. You want the mathematical operation of division for vv/yy, correct?! You should spell that out, otherwise people could easily interpret that as vv + “/“ + yy – Jeff Schaller Nov 2 '17 at 17:42
  • No its not the mathematical operation, but sign "/". i have added the headers also. Many Thanks. – aan Nov 2 '17 at 18:04

You can achieve what you want using a regex for the field separator. Assuming that : and ; are sub-field separators for fields 9 and 10 in the example you provided, here is an example of how to print out specific fields and sub-fields:

$ awk -F'[\t|;|:]' '{ print $1,$2,$4,$5,$18, $10, $16, $22 }' file
1 1278229 C A . SSC=7 FREQ 40%

Your current description of the sub-fields that you what is unclear and your sample output is even more unclear, but you should be able to modify my example to get the output you want.

  • Thanks fpmurphy for the solution. I thought of this, in my case each column has many sub columns (after splitting with respective delimiters) hence it was getting very difficult to count all the columns. I wanted sth where I could only count specific (needed) sub column from each column. – aan Nov 2 '17 at 15:43

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.