#!/bin/csh 

set dates = `cat msg1_new.txt | awk '{FS=","}{print $2}'`
set times = `cat msg1_new.txt | awk '{FS=","}{print $3}'`

set counter = 1
foreach date($dates)
   set longdate = `echo 20$date`

   set basemsg1 = `awk -v dd=$date -v tt=$times[$counter] 'BEGIN {FS=","};{if($2 ~ dd && $3 ~ tt) {print $0}}' msg1_new.txt`
   set basemsg2 = `awk -v dd=$date -v tt=$times[$counter] 'BEGIN {FS=","};{if($2 ~ dd && $3 ~ tt) {print $0}}' msg2_new.txt`
   set basemsg3 = `awk -v dd=$date -v tt=$times[$counter] 'BEGIN {FS=","};{if($2 ~ dd && $3 ~ tt) {print $0}}' msg3_new.txt`

   mkdir -p ../${longdate}

   echo $basemsg1,$basemsg2,$basemsg3 >> ../${longdate}/${longdate}S_L1.txt
   
   @ counter ++
   
   
   
end




exit(0)
