使用正则表达式删除表

时间:2013-04-18 16:27:42

标签: regex vim text

不是一个特定的问题,因为我不够了解 - 更多关于如何处理这个问题的问题。

示例文件如下所示:

 LOADING CONDITION :   4-Homogenous cargo 98% 1.018t/m3, draught 3.35m   
                       - outgoing               


                               ITEMS OF LOADING        
 -------------------------------------------------------------------------------
 CAPA  ITEM REFERENCE    X1      X2     WEIGHT    KG     LCG      YG       FSM  
  No                     (m)     (m)      (t)     (m)    (m)      (m)     (t.m) 
 -------------------------------------------------------------------------------
  13 No2 CARGO TK P      1.650  29.400   609.04  2.745  15.525  -3.384    483.49
  14 No2 CARGO TK S      1.650  29.400   603.61  2.745  15.525   3.384    483.49
  15 No1 CARGO TK P     29.400  56.400   587.23  2.745  42.900  -3.384    470.42
  16 No1 CARGO TK S     29.400  56.400   592.45  2.745  42.900   3.384    470.42
  17 MGO tank aft       21.150  23.400    23.42  6.531  22.275  -0.500     15.70
  18 TO storage tank    21.150  23.400     2.68  7.225  22.275   2.300      0.00
  19 MGO fore tank      33.150  35.400    25.90  6.643  34.275  -0.212      0.00
 -------------------------------------------------------------------------------
 DEADWEIGHT                             2444.34  2.828  29.007  -0.005   1923.52


                               SUMMARY OF LOADING      

                                        WEIGHT    KG     LCG      YG       FSM  
                                          (t)     (m)    (m)      (m)     (t.m) 
 -------------------------------------------------------------------------------
        DEADWEIGHT                      2444.34  2.828  29.007  -0.005   1923.52
        LIGHT SHIP                       634.00  3.030  28.654   0.000      0.00
 -------------------------------------------------------------------------------
        TOTAL WEIGHT                    3078.34  2.869  28.935  -0.004   1923.52





 LOADING CONDITION :   4-Homogenous cargo 98% 1.018t/m3, draught 3.35m   
                       - outgoing               
 Damage Case         : 1bott: all cargo & void3                          
 Flooding Percentage : 100 %
 Flooded Volumes     :   No.3 Void space P  No.3 Void space S  No2 CARGO TK P   
                         No2 CARGO TK S     No1 CARGO TK P     No1 CARGO TK S   


 -------------------------------------------------------------------------------
                            WEIGHT     KG      LCG      YG       FSM     CORR.KG
                              (t)      (m)     (m)      (m)     (t.m)       (m) 
 -------------------------------------------------------------------------------
 TOTAL WEIGHT               3078.34   2.869   28.935   -0.004    1923.52   3.494
 RUN-OFF WEIGHTS               0.00   0.000    0.000    0.000       0.00   0.000
 -------------------------------------------------------------------------------
 DAMAGE CONDITION           3078.34   2.869   28.935   -0.004    1923.52   3.494




 EQUILIBRIUM NOT FOUND ON STARBOARD                                             






 LOADING CASE :                                                                 
      4-Homogenous cargo 98% 1.018t/m3, draught 3.35m - outgoing                


 -------------------------------------------------------------------------------
                            WEIGHT     KG      LCG      YG       FSM     CORR.KG
                              (t)      (m)     (m)      (m)     (t.m)       (m) 
 -------------------------------------------------------------------------------
 TOTAL WEIGHT               3078.34   2.869   28.935   -0.004    1923.52   3.494


                    SUMMARY OF RESULTS OF DAMAGE STABILITY                      
 -------------------------------------------------------------------------------
       DAMAGE CASE               %  R  HEEL   GM     FBmin   GZ>0  GZmax  Area  
                                      (deg)   (m)     (m)   (deg)   (m)  (m.rad)
 -------------------------------------------------------------------------------
 1bott: all cargo & void3       100 0 EQUILIBRIUM NOT FOUND                     


 %     : 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.                                                      

它是许多中的一个,它们可以有所不同,但它们都以文本形式归结为表格。在将它们粘贴到报告中之前,我需要清理它们中的一些物品。

所以我想知道 - 删除某个表的文本方式是什么。例如,装载摘要(它以包含“装载摘要”的行开头,并以包含“总重量”的行结束。)

如何匹配该表并将其删除?

2 个答案:

答案 0 :(得分:4)

在vim中尝试以下内容

:g/SUMMARY OF LOADING/, /TOTAL WEIGHT/d

sed以同样的方式工作:

sed '/SUMMARY OF LOADING/, /TOTAL WEIGHT/d' input_with_tables.txt

答案 1 :(得分:0)

如果您需要删除所有此类表格,那么Fredrik Pihl的:g解决方案效果很好。对于更具体的编辑,您可以使用我的CountJump plugin通过定义开始和结束模式(例如您的SUMMARY OF LOADINGTOTAL WEIGHT)来创建自定义动作和文本对象,然后快速跳转到下一个表并删除带有快速映射的表。