1

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

1
  • If an input line was foo.bar.vivekski - should the grep output that line or not?
    – Ed Morton
    Commented Jul 6, 2019 at 17:29

1 Answer 1

1

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.

3
  • One more question. If i only want to look for "." than what should i use
    – Vivek Gaur
    Commented Jul 5, 2019 at 10:07
  • @VivekGaur a dot should be escaped, see my answer. Commented Jul 5, 2019 at 10:08
  • @VivekGaur If you mean a dot that is enclosed with spaces, use grep -E '(^|[[:space:]])\.($|[[:space:]])' Commented Jul 6, 2019 at 23:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.