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
  • 18,032
  • 4
  • 24
  • 37
FreelanceConsultant
  • 13,167
  • 27
  • 115
  • 225

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
  • 607,720
  • 39
  • 448
  • 563