Subscribers with Date 90 days older than current date

I have to display only those subscribers which are in "unconnected state" and the date is 90 days older than today's date.

Below command is used for this purpose:

cat vfsubscriber_20170817.csv | sed -e 's/^"//' -e '1d' | nawk -F '",' '{if ( (substr($11,2,4) == 2017) &&  ( substr($11,2,8) -lt $dm )&&($9=="\"unconnected") ) print $1,substr($11,2,8),$dm}' dm=$(perl -e 'use
    POSIX qw(strftime); print strftime "%Y%m%d",localtime(time()- 3600*24*90);') >  ${EXTRACT_FILE}

Problem is that this expression is not getting evaluated : `( substr($11,2,8) -lt $dm )`

dm=$(perl -e 'use
    POSIX qw(strftime); print strftime "%Y%m%d",localtime(time()- 3600*24*90);')

results into " 20170520 " which is correct.

Please help me to get this expression evaluated and compared correctly in the command.

Please become accustomed to provide decent context info of your problem.
It is always helpful to support a request with system info like OS and shell, related environment (variables, options), preferred tools, adequate (representative) sample input and desired output data and the logics connecting the two, and, if existent, system (error) messages verbatim, to avoid ambiguities and keep people from guessing.

I have extreme difficulties to understand what you're doing / trying up there. You seem to

  • mix up shell and awk syntax
  • use the dm variable before it is defined
  • not pass the variable correctly into the awk script.

Why do you use FOUR commands when the entire logics can be covered in one single only?

Where is the `( substr($11,2,8) -lt $dm )` construct (shell command substitution in its deprecated form) used?