不要介意奇怪的编码。
有没有一种方法(在这样的表格中,以 OF DAMAGE STABILITY 开头)并以“Flooding percentage”行结尾,以仅匹配最后一列中小于某个值(例如,0.018)的数字?
我正在练习正则表达式,但现阶段这对我来说太多了。所以我希望有人至少可以推荐什么是最好的解决方法。
SUMMARY OF RESULTS OF DAMAGE STABILITY
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
DAMAGE CASE % R HEEL GM FBmin GZ>0 GZmax Area
(deg) (m) (m) (deg) (m) (m.rad)
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
109.10s 100 1 -4.1 0.438 1.243 59.2 0.133 0.021
20 1 -6.6 0.740 2.215 63.4 0.479 0.049
40 1 -5.8 0.721 2.372 64.2 0.393 0.045
60 1 -3.2 0.728 2.537 66.8 0.277 0.041
80 1 -0.8 0.721 2.354 66.8 0.192 0.037
109.10p 100 1 -4.1 0.438 1.243 59.2 0.133 0.021
20 1 4.5 0.688 2.494 65.5 0.507 0.049
40 1 3.7 0.684 2.580 66.3 0.417 0.046
60 1 1.1 0.720 2.599 68.9 0.300 0.043
80 1 -1.2 0.693 2.350 65.2 0.177 0.035
110.10s 100 1 -3.0 0.748 1.837 39.7 0.494 0.049
20 1 -2.9 0.777 2.333 43.1 0.594 0.052
40 1 -2.9 0.777 2.333 42.5 0.576 0.052
60 1 -2.9 0.756 2.294 41.6 0.551 0.050
80 1 -2.9 0.748 2.077 40.7 0.520 0.049
110.10p 100 1 -0.5 0.733 2.143 41.6 0.484 0.047
20 1 -0.5 0.763 2.627 45.3 0.613 0.051
40 1 -0.5 0.763 2.627 44.7 0.592 0.051
60 1 -0.5 0.740 2.593 43.8 0.558 0.049
80 1 -0.5 0.767 2.372 42.7 0.516 0.048
% : Flooding percentage.
R : R=1 if run-off weights considered, R=0 if no run-off.
HEEL : Heel at equilibrium (negative if equilibrium is on port).
GM : GM at equilibrium.
FBmin : Minimum distance of margin line, weathertight or non-weathertight
points from waterline.
GZ>0 : Range of positive GZ limited to immersion of non-weathertight openings.
GZmax : Maximum GZ value.
最佳答案
0.018
这个例子不好,因为最后一列中的所有数字都大于 0.018
....我花了几分钟才找到它。我以为我的 vim 替换命令有问题...
查看示例,给定的范围边界(以 OF DAMAGE STABILITY 开始并以“Flooding percentage”结束)不是必需的,但您最了解要求。我也在命令中添加了范围。
在下面的命令中,我将其更改为 0.040
这样我们就可以看到差异。下面的命令将添加一个 *
在匹配号码的末尾。
/STABILITY/,/Flooding/s/\v([0-9.-]+)\s*$/\=str2float(submatch(1))<0.040? submatch(1).'*':submatch(1)
简要说明:
/STABILITY/,/Flooding/ " fit the range, as you defined
s/ " start substitution
\v " use very magic, so that I could save some escaping
([0-9.-]+)\s*$/ " match the last number column (float or negative)
\=str2float(submatch(1))<0.040? submatch(1).'*':submatch(1) " vimscript expression, if the value<0.040, add a '*'
如果你在 linux box 上,这个工作也很容易通过 awk 完成。如果您是 Microsoft 用户,Excel 可能(我不确定)是个好工具。
编辑
从您的评论来看,我认为您没有明白我的意思。我
命令:
/STABILITY/,/Flooding/s/\v([0-9.-]+\d)\s*$/\=str2float(submatch(1))<0.040? submatch(1).'<':submatch(1)/
然后你进行搜索:
/[0-9.-]\+\d\ze<$
注意这突出显示了数字(我仍然使用 0.040
来查看差异),同时添加标志/后缀 <
.您可以按 n
移动到下一个突出显示的号码.上一个 N
.如果你完成“阅读”文件,退出 :q!
或 ZQ
跳过更改。
希望这能满足您的要求。
看这个例子:
关于regex - 匹配正则表达式中表格中的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16560180/