Im using the grep
command In a simple script, the problem however Is that the string which the grep command Is searching for includes a square bracket character: [
.
After some research, i have found that the square bracket [
character is in fact used as a function for optimising the grep commands output through a process called "pipelining
" (Although don't quote me on It as Im not sure).
My Question:
How do I search for a string with a '[' character in it without invoking a pipelining function within grep?
Elaboration:
The script Is searching a system log for the string su[
. This Is my current malfunctioning command: tail -1 system.log | grep " su["
, however It will not work due to the square bracket at the end, returning the error: grep: brackets ([ ]) not balanced
.
Thanks In Advance.
Best Answer
Brackets should be escaped with
\
, because it's a special character. Your command will look like:Special characters
From this site You can learn about special characters in bash.
\
is a special character and it could be used as: