Vivek Gaur
Vivek Gaur

Reputation: 4787

how to search "." in a string using grep command

I have some string which include "." as part of it example

VCAT.VSCH.VIVEK 
VIVEK

I want to grep the sting which include ".vivek". i tried using grep -iw ".vivek" but it return no data. please help me finding the string.

Thanks in advance Vivek

Upvotes: 1

Views: 265

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 627180

You should remove w and use

s="VCAT.VSCH.VIVEK 
VIVEK"
grep -i '\.vivek' <<< "$s"
# => VCAT.VSCH.VIVEK 

See the online demo

Or, with a word boundary at the end to match vivek and not viveks:

grep -i '\.vivek\b' <<< "$s"

See another grep demo.

Upvotes: 1

Related Questions