How do you grep for a string containing a slash?

房东的猫 提交于 2019-12-04 01:00:58

You'll just need to escape the periods with a backslash. So if I have a file foo.txt with contents:

./.
foo
bar
./.

I can run grep \./\. test.txt, which should just print the two ./. lines.

The forward slash is not a special character in grep, but may be in tools like sed, Ruby, or Perl. You probably want to escape your literal periods, though, and it does no harm to escape the slash. This should work in all cases:

\.\/\.
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!