I have the following table
textA textB 1,21,41 10,30,50
textC textB 2,22,42,62 10,30,50,70
The values from the third column should be subtracted from those in the fourth column element-wise, i.e. 10-1, 30-21, 50-41; then 10-2, 30-22, 50-42, 70-62. The desired result should be printed in the fifth tab-separated column. The output table should look like
textA textB 1,21,41 10,30,50 9,9,9
textC textB 2,22,42,62 10,30,50,70 8,8,8,8
I have tried to combine some awk code lines:
(Pseudo-)code line one could theoretically subtract multiple values in one column, independently of how many values are in the column
awk '{for(i=1;i<=NF;i++)x-=$i;print x}' fileA
I now generate two independent files based on my third and fourth column
awk -F'\t' '{print $3}' fileA > fileB
awk -F'\t' '{print $4}' fileA > fileC
(Pseudo-)Code line three could theoretically process values from different files
awk 'NR==FNR{a[NR]=$1;next}{print $1+a[FNR],$2}' file1 file2
I try to combine code line one with code line three:
awk 'NR==FNR{a[NR]=$1;next}{print $1+a[FNR],{for(k=1;k<=NF;k++)z-=$i;print z}$2}' fileB fileC
That's where I got stuck. I'd be happy for any ideas.