I have a very long string and I want to find the first occurrence of a substring - but the substring contains double quotes. The only way of doing this that I'm familiar with is:
mystr='a very, very, extremely, incredibly long string of text that contains the phrase he said, "Hello!" somewhere in the middle' strpos=`expr index "$mystr" Hello` echo $strpos
which returns 92. But that won't work if the substring contains double quotes...
strpos=`expr index "$mystr" he said, "Hello`
I've tried escaping the double quotes (and the spaces). I've tried wrapping the string to find with single quotes. If I manage to run it without getting "unexpected EOF" or "syntax error", it returns a preposterous result like "2". (The position is somewhere in the thousands.) I'm guessing that I can't do what I'm trying to do with
expr index but if not, then how can I do it?