md168
asked on
grep for a string with a .
I'm grepping for spam URLs. I created a test file. I want to find ".ru/"
# cat file.txt
file.ru/
fileru/
# grep --regexp="[A-Za-z0-9].ru/" file.txt
file.ru/
fileru/
# grep -e ".ru/" file.txt
file.ru/
fileru/
How do I get grep to look for the period in ".ru/"?
# cat file.txt
file.ru/
fileru/
# grep --regexp="[A-Za-z0-9].ru/"
file.ru/
fileru/
# grep -e ".ru/" file.txt
file.ru/
fileru/
How do I get grep to look for the period in ".ru/"?
grep -e \.ru file.txt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Remember that in Regular Expressions, a dot (period) is a meta-character to match "any character".
Whenever you want to match a real character that happens to be a meta-character, you have to escape that meta-character by preceding it with a backslash.
Hopefully this helps
Whenever you want to match a real character that happens to be a meta-character, you have to escape that meta-character by preceding it with a backslash.
Hopefully this helps