Reformat a table with awk
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
and
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.
Vivek
• 1,043 views
•
link
0 answers
No answers yet.
Log in to answer this question.
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.
Cheers!
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".
input
Desired output, so that I can do some downstream analysis.
Hope this make sense,
Vivek
I got the answer needed.
Hope this helps someone!!
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.