I have a String like this
this_is_test_string1_22 this_is_also_test_string12_6
I wanted to split and extracts string around the last unders
You can do
s='this_is_test_string1_22'
In BASH:
echo "${s##*_}" 22
OR using sed:
sed 's/^.*_\([^_]*\)$/\1/' <<< 'this_is_test_string1_22' 22
EDIT for sh:
echo "$s" | sed 's/^.*_\([^_]*\)$/\1/'