Command grep is used for printing lines which matches to a pattern you have defined.
Exercise ::
For example there is one file name is test contains following lines.
is it test file ?
is it test file
Now pattern you defined is ? means you are trying to print all lines which contain ? (question mark) from file test.
Usually we try follow command.
cat test | grep ?
But output will show both lines because grep treat ? as single character both lines contains more than single character. Solution for grep lines containing ? (symbol) is define ?(special character) in []
cat test | grep [?]
is it test file ?
Same in case of all special character *, . , ‘ , ” , }, ) . This trick will help you when you need to search all lines containing defined pattern from log files. Also useful in shell scripting.













