SreeVik
SreeVik

Reputation: 73

Extract strings with exactly only two dots

I am looking to extract strings that have exactly 2 dots like below.

a.b.c

$$abc.$$def.123

The relevance is only to the dots.

So far i have tried

grep "\\.{2}" file_name.txt. 

But this is not giving me the result. Could you please help me

Upvotes: 0

Views: 263

Answers (1)

ryachza
ryachza

Reputation: 4540

I think this is just a regular expression issue. Your \.{2} will match two consecutive dots. What you'll probably want is something like:

^[^\.]*\.[^\.]*\.[^\.]*$

Which is "start of string, zero or more not-dots, a dot, zero or more not-dots, a dot, zero or more not-dots, end of string".

Upvotes: 1

Related Questions