0
嘿,我試圖找到文本文件中的記錄之間的距離。我試圖用awk來做到這一點。 一個例子是輸入:awk記錄之間的距離
1 2 1 4 yes
2 3 2 2 no
1 1 1 5 yes
4 2 4 0 no
5 1 0 1 no
我想找到的每個的數值之間的距離。我通過減去這些數值然後平分答案來做到這一點。我已經嘗試了下面的代碼,但所有的距離都只是0.任何幫助將不勝感激。
BEGIN {recs = 0; fieldnum = 5;}
{
recs++;
for(i=1;i<=NF;i++) {data[recs,i] = $i;}
}
END {
for(r=1;r<=recs;r++) {
for(f=1;f<fieldnum;f++) {
##find distances
for(t=1;t<=recs;t++) {
distance[r,t]+=((data[r,f] - data[t,f])*(data[r,f] - data[t,f]));
}
}
}
for(r=1;r<=recs;r++) {
for(t=1;t<recs;t++) {
##print distances
printf("distance between %d and %d is %d \n",r,t,distance[r,t]);
}
}
}
請包括一些示例輸出和_define_距離。 – Steve