19

How should I grep for a string containing a forward slash like ./.?

TRiG
  • 9,687
  • 6
  • 54
  • 105
LookIntoEast
  • 7,098
  • 16
  • 54
  • 84

3 Answers3

14

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:

\.\/\.
Todd A. Jacobs
  • 76,463
  • 14
  • 137
  • 188
12

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.

Peter
  • 1,309
  • 10
  • 20
0

Try fgrep. In your case fgrep '/<string>'

Mahaveer Jangir
  • 507
  • 6
  • 15