How to split string on forward slash in bash

bash, split, string

Solution

With `sed`:

$ echo "/gasg/string" | sed -e 's/\/.*\///g'
string

With buil-in bash string manipulation:

$ s="/gag/string"
$ echo "${s##/*/}"
string

Your strings look exactly like Unix pathnames. That's why you could also use the `basename` utility - it returnes the last portion of the given Unix pathname:

$ basename "/gag/string"
string
# It works with relative paths and spaces too:
$ basename "gag/fas das/string bla bla"
string bla bla

Problem

example String : /gasg/string expected result : `string` Characters to to remove: all characters between the "/" symbols including the symbols

Original source