Sum values average between patterns
Awk
approach:
awk '/pattern/{ if (cnt) { printf "%d\n", sum/cnt; sum=cnt=0 } print }
/^[0-9]+$/{ sum += $1; cnt++ }' file
The output:
pattern1
250
pattern2
166
pattern3
pattern4
Awk
approach:
awk '/pattern/{ if (cnt) { printf "%d\n", sum/cnt; sum=cnt=0 } print }
/^[0-9]+$/{ sum += $1; cnt++ }' file
The output:
pattern1
250
pattern2
166
pattern3
pattern4