I am aware, that this problem has been asked in slightly different ways many times before. But I couldn’t adapt those solutions.
I am having a file header.out with the following content:
// 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" ;
}
I need to extract the ID of the marker that belongs to the string “SymmetryPlane”
So in this case i want to have 6 as the output. All tries using sed and regular expressions failed.
What i have tried is:
sed 's/.*marker_\(.*\) = "SymmetryPlane.*/\1/' header.out
But this only gives me
: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" ;
}
I am not sure why this is happening.
Thanks in advance!
Just suppress the output (
-n) and print after substitution (p):