awk to print mon and max values of ranges
HI all
I'm trying to write an awk script to print the min and max value in a range(s) contained in another file - the range values are in $2
EG
114,7964,1,y,y,n
114,7965,1,y,y,n
114,7966,1,y,y,n
114,7967,1,y,y,n
114,7969,1,y,y,n
114,7970,1,y,y,n
114,7971,1,y,y,n
114,7972,1,y,y,n
114,7973,1,y,y,n
114,7974,1,y,y,n
114,7977,1,y,y,n
114,7980,1,y,y,n
114,7981,1,y,y,n
114,7983,1,y,y,n
The output should produce
7964
7967
7969
7974
7977
7977
7980
7983
Or ideally
7964 - 7967
7969 - 7974
7977
7980 - 7983
SO far I have this awk script
BEGIN{
FS=OFS=","
nxt=0
}
$2!=nxt {print $2;tmp=$2;nxt=int($2+1)}
Which produces the wrong max figure
i.e.
7964
7966
7969
7971
7973
etc .....
Note the extra 7971 ??
Any advice ??
thanks