Checking File record equal to multiple of 70 or nearest number to multiple of 70

Hello,

I have a file with below content - Example

3
6
69
139
210
345
395
418
490
492

I would like the result as - Multiple of 70 or nearest number in the file less than the multiple of 70

69
139
210
345
418
490

I tried using awk but doesn't succeed in getting result. Please try and let me know the way if we could achieve the result in unix.

Thanks,
Mannu

I'm not getting your approach to create the output - could you post your existing code?
Otherwise your definition of nearest (when number modulo 70 is not equal to zero) would help.

I think I see the pattern, but I don't understand why the desired output doesn't include the final line:

492

If you wanted that final line as well as the output you said you wanted, you could try something like:

awk '
NR == 1 || $1 > m {
	if(NR > 1)
		print v
	m = int(($1 + 69)/70) * 70
}
{	v = $1
}
END {	print v
}' file

which, if file contains your sample data, produces the output:

69
139
210
345
418
490
492
1 Like

try also:

awk '
{
l=$1 % 70; if (! l ) c[NR]=d[NR]=1;
n[NR]=$1; m[NR]=l
}
END {
   c[0]=d[0]=c[NR+1]=d[NR+1]=70;
   for (i=0; i<NR; i++) if (m[i+1] <= m) c=1
   for (i=NR; i>1; i--) if (m[i-1] <= m) d=1
   for (i=1; i<=NR; i++) if (c && d) print n
}
' infile
1 Like

Try also

awk '{T[int(($1-1)/70)] = $1} END {for (t in T) print T[t]}' file
69
139
210
345
418
490
492
2 Likes

Thank you Don Cragun , rdrtx1 and RudiC.