数据无效的线性插值

Linear interpolate where data is invalid

我想仅在数据等于“---”的情况下基于上一个和下一个已知值对单个列进行线性插值。

数据示例:

0
---
---
---
10
---
20
22
15
---
---
---
-15

想要的输出:

0
2.5
5
7.5
10
15
20
22
15
7.5
0
-7.5
-15

我见过可以根据第一列(例如日期)进行插值的代码,如 here. And other codes that would do it for step size, like here 所述,但它们对我不起作用。提前致谢!

awk 救援!

$ awk '!/---/ {n=c; while(c&&c--) print v+(n-c)*(-v)/(n+1); v=; print } 
        /---/ {c++}' file

0
2.5
5
7.5
10
15
20
22
15
7.5
0
-7.5
-15