https://stackoverflow.com/questions/19482123/extract-part-of-a-string-using-bash-cut-split
Examples:
Given a variable like
MYVAR="users/joebloggs/domain.com"
Remove the path leaving file name (all characters up to a slash):
echo ${MYVAR##*/}
domain.com
Remove the file name, leaving the path (delete shortest match after last /
):
echo ${MYVAR%/*}
users/joebloggs
Get just the file extension (remove all before last period):
echo ${MYVAR##*.}
com
NOTE: To do two operations, you can’t combine them, but have to assign to an intermediate variable. So to get the file name without path or extension:
NAME=${MYVAR##*/} # remove part before last slash
echo ${NAME%.*} # from the new var remove the part after the last period
domain