I want to get two latest words from a string variable.
Total number of words in the string variable is not constant.
This is what I try:
LIST=`some command`
LATEST1=""
LATEST2=""
for ITEM in $LIST
do
LATEST2="$LATEST1"
LATEST1="$ITEM"
done
echo "Latest: $LATEST1"
echo "2nd latest: $LATEST2"
But it is slow. Is there any better way to do it?
sh shell of busybox is used. Other scripting languages are not available.
Regex which will match the last 2 words (including whitespaces in this case)