0

I want to grep for a string which begins with a colon :, the contains 0 or more characters of anything, and then ends with the string mystring.

I tried this: grep -rI ':*mystring' . but this did not work.

From searching, I believe the reason this does not work is because it is matching "0 or more instances of the colon character : followed by mystring. (See an answer on this question)

That doesn't make much sense to me, hence my question.

Edit: None of the answers in the linked question solve this problem. There is no mention of matching a colon character, and trying to adapt the answers does not work either.

Ryszard Czech
  • 16,363
  • 2
  • 17
  • 35
FreelanceConsultant
  • 11,249
  • 25
  • 98
  • 189

1 Answers1

0

You can use

grep -rI '^:.*mystring' file

Details:

  • ^ - start of string
  • : - a colon
  • .* - any zero or more chars
  • mystring - a string.
Wiktor Stribiżew
  • 561,645
  • 34
  • 376
  • 476