Q:

How to cut year and month from file name

How to cut the Year and Month from file name like ABC_PQRS_XYZ_2016_09
and take the value in 2 variables like:
ABC_PQRS_XYZ_2016_09

year=2016
Month = 09

A:

In Bash
filename='ABC_PQRS_XYZ_2016_09'
month="${filename: -2}"
year="${filename: -7:4}"

printf "year: %s\nmonth: %s\n" "$year" "$month"

Output
year: 2016
month: 09

Portable version
year="${filename%*_*}"
year="${year##*_}"
month="${filename##*_}"

printf "year: %s\nmonth: %s\n" "$year" "$month"

P.S.
In comments to another answer, you have mentioned that you actually have a filename with .txt extension. Extension can be cut off using basename command:
filename=$(basename "$filename")

