How to fix "grep: Unmatched [, [^, [:, [., or [=" error when using regex

I am trying to located [items1, [items2 and such terms in all files. So I typed the following at shell prompt:

grep '[items' *

I am not sure by the following message on screen:

grep: Unmatched [, [^, [:, [., or [=

How to fix it?

When you need to match [ escape it by adding \. For instance:

grep '\[items' *
1 Like

When using grep regular expression, [ act as a special character. Do you need [? Then add a backslash to escape it. Check BRE page Regular Expressions

1 Like

Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki