Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shell script substring from first indexof substring

I want to accomplish the equivalent of the following pseudo-code in bash (both a and b are inputs to my script) :

String a = "some long string";
String b = "ri";
print (a.substring(a.firstIndexOf(b), a.length()); //prints 'ring'

How can I do this in shell script?

like image 215
pathikrit Avatar asked Apr 27 '12 10:04

pathikrit


1 Answers

Try:

    $ a="some long string"
    $ b="ri"

    $ echo ${a/*$b/$b}
    ring

    $ echo ${a/$b*/$b}
    some long stri
like image 169
Josshad Avatar answered Oct 22 '22 18:10

Josshad