-1

我知道,这个问题以前曾多次以略有不同的方式提出。但我无法适应这些解决方案。我有一个包含以下内容的文件 header.out:

// some text before this 
            :type = "Primary Grid: Tau Format" ;
            :deformation_timestep = 0. ;
            :deformation_alpha = 0. ;
            :deformation_dalpha = 0. ;
            :deformation_h = 0. ;
            :deformation_dh = 0. ;
            :deformation_step = 0 ;
            :adaptation_level = 0 ;
            :connectivity_check = 1 ;
            :volume_check = 1 ;
            :point_check = 1 ;
            :test_lib_check = 1 ;
            :periodic_pairs_check = 1 ;
            :is_balanced = 0 ;
            :preserve_piles = 0 ;
            :marker_1 = "WingMidTrailing" ;
            :marker_2 = "WingMidLower" ;
            :marker_3 = "WingMidUpper" ;
            :marker_4 = "WingSide" ;
            :marker_5 = "Farfield" ;
            :marker_6 = "SymmetryPlane" ;
            :marker_7 = "WingInnerLower" ;
            :marker_8 = "WingInnerUpper" ;
            :marker_9 = "WingInnerTrailing" ;
            :marker_10 = "WingOuterLower" ;
            :marker_11 = "WingOuterUpper" ;
            :marker_12 = "WingOuterTrailing" ;
 }

我需要提取属于字符串“SymmetryPlane”的标记的 ID 所以在这种情况下,我想要 6 作为输出。所有使用 sed 和正则表达式的尝试都失败了。我试过的是:

sed 's/.*marker_\(.*\) = "SymmetryPlane.*/\1/' header.out

但这只会给我

            :type = "Primary Grid: Tau Format" ;
            :deformation_timestep = 0. ;
            :deformation_alpha = 0. ;
            :deformation_dalpha = 0. ;
            :deformation_h = 0. ;
            :deformation_dh = 0. ;
            :deformation_step = 0 ;
            :adaptation_level = 0 ;
            :connectivity_check = 1 ;
            :volume_check = 1 ;
            :point_check = 1 ;
            :test_lib_check = 1 ;
            :periodic_pairs_check = 1 ;
            :is_balanced = 0 ;
            :preserve_piles = 0 ;
            :marker_1 = "WingMidTrailing" ;
            :marker_2 = "WingMidLower" ;
            :marker_3 = "WingMidUpper" ;
            :marker_4 = "WingSide" ;
            :marker_5 = "Farfield" ;
6
            :marker_7 = "WingInnerLower" ;
            :marker_8 = "WingInnerUpper" ;
            :marker_9 = "WingInnerTrailing" ;
            :marker_10 = "WingOuterLower" ;
            :marker_11 = "WingOuterUpper" ;
            :marker_12 = "WingOuterTrailing" ;
}

我不确定为什么会这样。

提前致谢!

4

1 回答 1

2

只需抑制输出 ( -n) 并在替换 ( p) 后打印:

sed -n 's/.*marker_\(.*\) = "SymmetryPlane.*/\1/p' header.out
于 2012-12-03T08:29:06.390 回答