Shell script substring from first indexof substring
grep
, sed
and so on can be used but it is not pure-bash.
expr
is a good choice but index
parameter is not, because it matches character not the whole string, try with a = "some wrong string"
it matches the first r
.
Instead use expr match
with its regular expression parameter :
a="some long string";b="ri";echo ${a:$(expr match "$a" ".*${b}") - $(expr length "$b")}
It also works with a = "some wrong string"