Off topic:Reformat a table with awk
0
0
Entering edit mode
7.0 years ago
viv3kanand ▴ 10

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

awk • 949 views
ADD COMMENT
This thread is not open. No new answers may be added
Traffic: 2564 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6