Skip to main content
edited title
Link
Michael Durrant
  • 43.7k
  • 72
  • 176
  • 237

sed - how to (not) match unmatched brackets

Source Link
Michael Durrant
  • 43.7k
  • 72
  • 176
  • 237

sed - how to match unmatched brackets

How can I do my operation only on lines that close their brackets?

For example I want to change ".is" lines and add a bracket but not for lines with unclosed brackets.

so these are changed

this_thing.is 24  ->   (this_thing).is 24
that.is 50        ->   (that).is 50
a[23].is == 10    ->     a[23].is == 10
a.is true         ->   (this_thing).is 24
this_thing.is 24  ->   (this_thing).is 24

but these aren't:

this_thing.is (24
((that).is 50
(a[23].is == 10
a.is ( true
(this_thing.is 24

ideally also (not)

a{.is true
this_thing{.is 24

and (not)

a[.is true
this_thing[.is 24 

I have a matcher with /.is/ but how to match unmatched brackets?