Search code examples
linuxunixgrep

I want to display lines that contain a single bracket either its opening or closing


Like I am having a data like

1 -> (abc
 2-> abc)

one having opening parenthesis and 2 having closing parenthesis.

I am expecting like I have txt file I have both mistakes while entering and missing want to echo all the occurrence of opening but absence of closing while another one is if only closing present. I am using bash code but it only shows for occurrence of opening but absence of closing parenthesis my code is grep -E '^[^()]*\([^()]*$|^[^()]*[^()]*\([^()]*$' and this shows only result for ( abc
but not for abc). please help me out Thanks.


Solution

  • Perhaps this regex is what you are looking for

    grep -E '^[^()]*[()]{1}[^()]*$'