Question: (Closed) Reformat a table with awk
gravatar for viv3kanand
22 months ago by
viv3kanand10 wrote:

Hi, I have this table,

ID ref1 ref2
a   1   3
b   3   1
c   5   1
d   2   4

Tab seperated and there are n number of IDs (a,b,c,..) and references (ref1,ref2,... and so on). I want to replace the numbers with its corresponding ID if greater than 2, so the desired output will be like,

ref1 ref2
b     a
c     d

I have manged to do for single columns with awk

awk -F "\t" '{if($2>2) print $1}' filename


awk 'BEGIN{OFS=FS="\t"}$2>2{$2=$1}{print}' filename

But I can't use them for larger files.

Any help is much appreciated, Thank you.


awk • 530 views
ADD COMMENTlink written 22 months ago by viv3kanand10

Hello viv3kanand!

We believe that this post does not fit the main topic of this site.

This is not a bioinformatics question. Please search stackoverflow

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.


ADD REPLYlink written 22 months ago by RamRS20k

Hi Ram,

From TCGA I got data similar as the table I mentioned. Down below I have converted the mentioned table into real data. Please recheck the fitness of the question to be a main topic so called "bioinformatics".


TCGA_ID                 CEPNA     AKT1
tcga-01-01a-1245    1.677        3.531
tcga-01-01a-1243    3.765        1.433
tcga-01-01a-1242    5.311        1.234
tcga-01-01a-1241    2.153        4.5656

Desired output, so that I can do some downstream analysis.

CEPNA                   AKT1
tcga-01-01a-1243   tcga-01-01a-1245
tcga-01-01a-1242   tcga-01-01a-1241

Hope this make sense,


ADD REPLYlink modified 22 months ago • written 22 months ago by viv3kanand10

I got the answer needed.

awk 'BEGIN{FS=OFS="\t"}NR>1{for(i=2;i<=NF;i++) if ($i>2) { $i=$1 } else { $i="NIL" } }1' filename

Hope this helps someone!!

ADD REPLYlink modified 22 months ago • written 22 months ago by viv3kanand10

I'm glad you got a solution. The data in your file alone does not make this bioinformatics. I'd also try and cut down on the sarcasm - that does not play well on online forums.

ADD REPLYlink written 22 months ago by RamRS20k
Please log in to add an answer.
The thread is closed. No new answers may be added.


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