With pure Bash, it's a little long:
IFS="-" read -r -a arr <<< "abc-ananya-01" last=10#${arr[${#arr}-1]} # to prevent getting 08, when Bash # understands it is a number in base 8 last=$(( last + 1 )) arr[${#arr}-1]=$(printf "%02d" $last) ( IFS="-"; echo "${arr[*]}" )
It reads into an array, increments the last element and prints it.
It returns:
abc-ananya-02
fedorqui
source share