so i have a code that identifies which value is the closest to a value provided by the user.
awk -F"," -v c=${COLUMN} -v t=${USTIME} '{a[NR]=$c}END{
asort(a);d=a[NR]-t;d=d<0?-d:d;v = a[NR]
for(i=NR-1;i>=1;i--){
m=a-t;m=m<0?-m:m
if(m<d){
d=m;v=a
}
}
print v
}' data.file
content of data file:
blah1,blah1,1453745100,blah1,blah1,blah1
blah2,blah2,1453745196,blah2,blah2,blah2
blah3,blah3,1453745296,blah3,blah3,blah3
blah4,blah4,1453745396,blah4,blah4,blah4
right now, this code only outputs the value that it finds to be closest. but i want it to output the entire line from which that value is found.
so, say, this code outputted 1453745196. Instead of that, i want it to output
blah2,blah2,1453745196,blah2,blah2,blah2