extract the relevant data files for a quarter

CTB_KT_OllyotLvos_20081204_164352_200811.txt
CTB_KT_LN_utahfwd_20081204_164352_200811.txt
CTB_KT_LN_utahfwd_Summ_20081204_164352_200811.txt
CTB_KT_PML_astdt_prFr_20081204_210153_200811.txt
CTB_KT_PML_astdt_prOt_20081204_210153_200811.txt
CTB_KT_PML_astdt_Nopr_20081204_210153_200811.txt
CTB_KT_OllyotLvos_20090111_064702_200812.txt
CTB_KT_LN_utahfwd_20090111_064702_200812.txt
CTB_KT_LN_utahfwd_Summ_20090111_064702_200812.txt
CTB_KT_PML_astdt_prFr_20090112_105344_200812.txt
CTB_KT_PML_astdt_prOt_20090112_105344_200812.txt
CTB_KT_PML_astdt_Nopr_20090112_105344_200812.txt
CTB_KT_OllyotLvos_20090205_145545_200901.txt
CTB_KT_LN_utahfwd_20090205_145545_200901.txt
CTB_KT_LN_utahfwd_Summ_20090205_145545_200901.txt
CTB_KT_PML_astdt_prFr_20090206_010203_200901.txt
CTB_KT_PML_astdt_prOt_20090206_010203_200901.txt
CTB_KT_PML_astdt_Nopr_20090206_010203_200901.txt

This is a set of files in test directory.
format of filename: string_yyyymmdd_hhmmss_previousyearmonth.txt. The yyyymmdd has to be used.
The requirement is get all the files which arrived in a given quarter.So if the quarter is 3 then all files which have arrived in Jan Feb Mar.The files date has to be taken from the file nameSo If I run this for 1st quarter then I should get these files out of the above set. the quarter can be calculated for a field $d which is the last day of the quarter.

CTB_KT_OllyotLvos_20090111_064702_200812.txt
CTB_KT_LN_utahfwd_20090111_064702_200812.txt
CTB_KT_LN_utahfwd_Summ_20090111_064702_200812.txt
CTB_KT_PML_astdt_prFr_20090112_105344_200812.txt
CTB_KT_PML_astdt_prOt_20090112_105344_200812.txt
CTB_KT_PML_astdt_Nopr_20090112_105344_200812.txt
CTB_KT_OllyotLvos_20090205_145545_200901.txt
CTB_KT_LN_utahfwd_20090205_145545_200901.txt
CTB_KT_LN_utahfwd_Summ_20090205_145545_200901.txt
CTB_KT_PML_astdt_prFr_20090206_010203_200901.txt
CTB_KT_PML_astdt_prOt_20090206_010203_200901.txt
CTB_KT_PML_astdt_Nopr_20090206_010203_200901.txt

Try this:

awk -F_ '{
  for(i=1;i<=NF;i++) {
    if(int($i)) {
      q=int(((substr($i,5,2))+2)/3)
      break
    }
  }
}
q==quarter
' quarter=1 datafile

Regards

Pls help in understanding this program.What is the datafile?

Replace "datafile" with your filename(s).

Regards

This would return files for first quarter for all the years. I would require that on the basis of end of period ie. if the qtr end date is mar 31 2009 then jan 2009 feb 2009 and mar 2009 should be selected and should not include files from preious year for the same qtr.
Thanks

Its returning all the files. I just require files for that particular qtr.

Thanks

/bin/ls -l |
  grep '_200090[123].._'

Please, don't bump up questions, that's agains our rules.

Try to understand the code. With the given example you should be able to enhance it to fulfill your requirements. It is suggested that you learn by reading and experiencing it yourself, not always asking for the right answer. If you get stuck with a piece of the code, don't hestitate to ask.

Regards