I have a document containing { and } throughout, but I found there are mistakes. I used grep -c { * and grep -c } * to find that the number of { and } is not equal. I want to find those lines with possible errors, so I can manually check them.
- The closing braces should always appear on the same line, so I need to find lines with
{that don’t have a closing}or lines with}without the opening brace. - Some lines have many braces, e.g.
{ } { } { }. - There never should be nested braces, e.g. `{ { { } } }’.
How can I search for lines that do not have the correct number of braces?
You can do something like this (This will print the line and the line number) –
Test: