LookIntoEast
LookIntoEast

Reputation: 8808

How do you grep for a string containing a slash?

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

Upvotes: 23

Views: 68534

Answers (3)

Mahaveer Jangir
Mahaveer Jangir

Reputation: 605

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

Upvotes: 0

Todd A. Jacobs
Todd A. Jacobs

Reputation: 84423

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:

\.\/\.

Upvotes: 15

Peter
Peter

Reputation: 1359

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.

Upvotes: 13

Related Questions