I have table with values and I have to find match: first column with others and print the match.
INPUT:
A:0 A:0.7541 A:0.7396 A:0.7694
A:0 0:0 0:0 0:0
C:0 C:0.8408 C:0.8459 C:0.7939
G:0 G:0.3415 G:0.3290 G:0.4228
G:0 G:0.0343 G:0.0378 T:8.237e06,G:0.02437
C:0 C:0.3895 C:0.3837 A:8.255e06,T:8.255e06,C:0.3623
OUTPUT:
A:0 0.7541 0.7396 0.7694
A:0 0 0 0
C:0 0.8408 0.8459 0.7939
G:0 0.3415 0.3290 0.4228
G:0 0.0343 0.0378 0.02437
C:0 0.3895 0.3837 0.3623
For last row.. if C is in the second column, print only number after matching letter C in this case, same for all columns, but there could be more values separated by ",". So print only the number which contain the match letter C in this case for this row. I wrote :
awk '{split ($1,a,":");split ($2,b,":"); split($3,c,":"); split($4,d,":");
if(a[1]=b[1] && a[1]=c[1] && a[1]==d[1]) print $0}' /home/fil/Desktop/uprava.txt
awk to the rescue!
$ awk '{key=substr($1,1,2);
n=split($NF,last,",");
if(n>1) for(i=1;i<=n;i++) if(last[i]~key) {$NF=last[i]; break}
for(i=2;i<=NF;i++) sub(key,"",$i);
print}' file | column -t
A:0 0.7541 0.7396 0.7694
A:0 0:0 0:0 0:0
C:0 0.8408 0.8459 0.7939
G:0 0.3415 0.3290 0.4228
G:0 0.0343 0.0378 0.02437
C:0 0.3895 0.3837 0.3623
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With