Suppose I have the string 1:2:3:4:5 and I want to get its last field (5 in this case). How do I do that using Bash? I tried cut, but I
1:2:3:4:5
5
cut
It's difficult to get the last field using cut, but here are some solutions in awk and perl
echo 1:2:3:4:5 | awk -F: '{print $NF}' echo 1:2:3:4:5 | perl -F: -wane 'print $F[-1]'