extract last 8 characters from a file name

Dear gurus

I have several files with the following format filenameCCYYMMDD , that is the last 8 characters will be the date in CCYYMMDD format. eg FILENAME20110523 .
Could anyone please put me through on how to extract only the last 8 characters from the files.
I am thinking of using awk,sed or perl but do not know how to write the code.

Thanks in anticipation !

If you have gnu grep

tail -1 filename | grep -Eo '.{8}$'
1 Like
# a=whatever20110520
# t=${a%????????}
# echo ${a##$t}
20110520
# echo $a | tail -c 9
20110520
# echo $a | cut -c$((${#a}-8+1))-
20110520
# echo $a | sed 's/.*\(........\)$/\1/'
20110520
1 Like