I intend to add further explanation regarding the OP attempts and other answers.
You can use John Kugelmans solution like this:
grep -x "ABB\.log" a.tmp
quoting the line and avoiding the period ( . ), the -F flag is no longer needed.
You need to avoid . (period) (because it matches any character (not only . ) if not escaped) or use the -F flag with grep. The -F flag makes it a fixed string (not a regular expression).
If you don't quote the line, you may need a double backslash to escape the dot ( . ):
grep -x ABB\\.log a.tmp
Test:
$ echo "ABBElog"|grep -x ABB.log ABBElog #matched !!! $ echo "ABBElog"|grep -x "ABB\.log" #returns empty string, no match
Note:
-x forces the entire line.- Answers using unshielded
. without the -F flag erroneous. - You can avoid the
-x switch by wrapping the pattern string with ^ and $ . In this case, make sure that you do not use -F , but avoid . , because -F will interfere with the interpretation of the ^ and $ regular expressions.
EDIT: (Adding further explanation regarding @hakre):
If you want to combine a line starting with - then you should use -- with grep. Everything that follows -- will be taken as an input (not an option).
Example:
echo -f |grep -- "-f" # where grep "-f" will show error echo -f |grep -F -- "-f" # whre grep -F "-f" will show error grep "pat" -- "-file" # grep "pat" "-file" won't work. -file is the filename
Jahid Jul 12 '15 at 14:28 2015-07-12 14:28
source share