Right now I have this:
echo "silly/horse/fox" | cut -d "/" -f3
fox
But I want to be able to get the last string no matter how many delimiters we have.
So something like "silly/horse/fox/lion" would return me "lion"
Something of an equivalent to Python's string.split('/')[-1]
Pure bash
solution:
$ foo="silly/horse/fox"
$ echo ${foo##*/}
fox
$ foo="silly/horse/fox/lion"
$ echo ${foo##*/}
lion
Using sed
:
$ echo "silly/horse/fox/lion" | sed 's#.*/##'
lion
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