If I want to search for a string which contains a dot, in command line I can just prepend it with a backslash:
grep "string\." file.txt
or add -F -r
parameters:
grep -F -r "string." file.txt
but there seems to be a problem if I want to use grep -f
and have strings with dots inside the file with patterns.
I tried using quotes, prepending all the dots in the file with a backslash and using grep -F -r -f
and even messed a bit with -E
but none of these match the strings correctly without interpreting the dots as special characters.
How to achieve the desired behavior?
Insert a \\
before .
:
grep -f <(sed 's/\./\\./g' file_with_dots_inside.txt) file.txt
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.