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?
Try:
$ a="some long string"
$ b="ri"
$ echo ${a/*$b/$b}
ring
$ echo ${a/$b*/$b}
some long stri
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With