awk - Regex to delete a line -


i have following pattern :

"gear_size"=>"small", "gear_size"=>"medium", "name"=>"node.cip4pc.cisco.com", "region_name"=>"ccs", "gear_size"=>"large", node.cip4pc.cisco.com:10.203.24.175, 

i need delete line "gear_size"=>"small", , "gear_size"=>"large",.
these 2 lines don't have "name"=> pattern getting followed.
so, need delete line "gear_size" not followed "name".
i checked if command pcregrep works, command not supported.
getting resolved great.
thanks.

edit: better solution if need name come directly after

sed '/^"gear_size"/{n;/\n"name"=>/!d}' 

if line matches /^"gear_size"/, , next line doesn't match /^"name"=>/, delete it.

original: horrible solution separation between gear_size , name

sed '/gear_size/{h;d};/name/{x;/^$/!{p;s/.*//};x}' file 

output:

"gear_size"=>"medium", "name"=>"node.cip4pc.cisco.com", "region_name"=>"ccs", node.cip4pc.cisco.com:10.203.24.175, 

explanation:

replace hold space line matching /gear_size/ , delete line (moves next line without printing).

if line matches /name/, swap line hold space. if hold space not empty, print contained , empty it. swap back.

then, contents of pattern space printed default.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -