Cut last 7 characters of a variable

I need to cut the last seven characters of a variable length variable. The variable may be 7 characters or 70. I need to always be able to grab the last 7 characters. I looked at the cut command but it always seems to want to start at the beginning of a line, not the end and count backwards.

Anyone know how to do this with cut? Awk? Sed? something else?

 
echo "${var}' | awk '{print substr($0,length($0)-7,7)}'
1 Like
 
value=$(echo ${orig_value} | sed 's/.*\(.......\)$/\1/')
bash --version
GNU bash, version 4.1.5(1)-release (i486-pc-linux-gnu)
echo ${Variable:(-7)}

will return the 7 last chars of Variable

The awk command didn't give me the last 7 characters. It gave me the first seven characters. The sed command worked though. Thanks all

here is working example with awk

echo $var | awk '{print substr($0,length($0)- 6,length($0))}'

echo 1ddddddddddddddddddddddd1111111234567 | awk '{print substr($0,length($0)- 6,length($0))}'
1234567