#!/bin/bash ## subsetMBRStoSMALL -- used from generateElistFromHISTORY+MBRS -- Eugene Reimer 2007-Mar; ## ## note: Peggy sends 2 kinds, which i refer to as: ## BIG -- all membership records since 2000-Jan -- i give these filenames containing "BIG" ## SMALL -- only the current In-Good-Standing members -- i give these filenames without BIG -- also without SMALL:-) ## -- whereas her "small" contains only In-Good-Standing members, ## my SMALL constructed from a BIG, includes those delinquent by less than a year -- BUT ONLY early in the year (Jan..May); ## ## USAGE: ## subsetMBRStoSMALL BIG-htmfile DEST-SMALL-htmfile <-- only because generateElist script had both names handy:-) BIG=$1; DST=$2; [ $# -ne 2 ] && { echo "usage subsetMBRStoSMALL BIG-htmfile DEST-SMALL-htmfile"; exit; } ##set -v ##YY=$(date +%y); MM=$(date +%m) ##get current year YY, month MM, and PP=(YY-1) (pre-07oct) MDATE=${BIG/MBRS/}; MDATE=${MDATE/-BIG/}; MDATE=${MDATE%%.*} ##get MDATE from the input MBRS-db-name (07oct) YY=${MDATE:2:2};yy=10#$YY; MM=${MDATE:4:2};mm=10#$MM ##get year YY and month MM from the input MBRS-db-name (07oct) ((P=yy-1)); PP=$(printf "%02d" $P);pp=10#$PP ##get previous year PP = (YY-1) echo -n "subsetMBRStoSMALL: YY=$YY MM=$MM PP=$PP -- continue??"; read ##DEBUG 07oct ## COLUMNS: eg: to select those who paid dues for 2005 or 2006, test for columns 32 or 34 non-null; ## Dues2004 is col 29 ## Dues2005 is col 32 -- since 2005, she's been adding exactly 2-columns per year (previously she added 3 per year) ## Dues2006 is col 34 ## Dues2007 is col 36 (I hope it will be) ## DERIVE column-nbrs from the year: Dues-YY is col 32+2*(YY-05) <--EVEN BETTER WOULD BE to find the "Dues YYYY" heading in first row of table?? ## ## ALGORITHM: When MM < 06, then select based on Dues-YY-1 OR Dues-YY; when MM>=06, use only Dues-YY; ## ((DuesYY= 32 + 2 * (yy-5) )) ##Dues-column-nbr for current-year YY ((DuesPP= 32 + 2 * (pp-5) )) ##Dues-column-nbr for previous-year PP grep '||; s||~|g' |tr '~' '\n' >tmpColHeadings ##write ColHeadings temp-file, for checking... hdgYY=$(head -n$DuesYY tmpColHeadings |tail -n1) ##Dues-column-contents for year YY from the ColHeadings hdgPP=$(head -n$DuesPP tmpColHeadings |tail -n1) ##Dues-column-contents for year PP from the ColHeadings if [[ $hdgYY != 20${YY}Dues* ]];then echo "subsetMBRStoSMALL: column$DuesYY: EXPECTING:20${YY}DuesDate, FOUND:$hdgYY"; fi ##expect hdgYY to be 20${YY}DuesDate if [[ $hdgPP != 20${PP}Dues* ]];then echo "subsetMBRStoSMALL: column$DuesPP: EXPECTING:20${PP}DuesDate, FOUND:$hdgPP"; fi ##expect hdgPP to be 20${PP}DuesDate if ((mm<6)); then ##--Month is Jan..May, select BadStanding as well as GoodStanding members cat $BIG | sed 's| |~|g; s| ||g' | ##field kludges awk '{ if(NF<34 || $'$DuesPP'!~" " || $'$DuesYY'!~" ") print $0 }'| ##select if DuesPP or DuesYY NON-null sed 's|~| |g' >$DST else ##--Month is Jun..Dec, select GoodStanding members only cat $BIG | sed 's| |~|g; s| ||g' | ##field kludges awk '{ if(NF<34 || $'$DuesYY'!~" ") print $0 }' | ##select if DuesYY NON-null sed 's|~| |g' >$DST fi echo -n "subsetMBRStoSMALL: Counting lines in Received-BIG:"; wc $BIG ##DEBUG echo -n "subsetMBRStoSMALL: Counting lines in Subsetted-SMALL:"; wc $DST ##DEBUG exit ==might be nicer to call this from (or incorporate into) fixPeggyMBRS; it can then do: (1) renaming to BIG if needed, as well as (2) subsetting to SMALL by time-of-year rules (this scipt); 2007-Oct: time-of-year rules now based on DATE-of-Peggys-XLS database (NOT date of emailing); --may also revise the cutoff: Early==Jan..APRIL (rather than Jan..May)--??-- note: ONCE A YEAR, will send a special "renewal needed" reminder to BS-members, AND remove them from the Elist - say in April or May? => early in the year, construct Elist from GS+BS mbrs; but after the "renewal needed" reminder, construct it from GS only; NOTE: in 06may, besides BadStanding cases to be removed, also had some long-Lapsed ex-members! because I had started with 04feb list... did the 06may removal using output from classifyElistIDs, fed through grep+sed... 2007-Oct: have automated producing such ToBeRemoved list, in generateElistFromHISTORY+MBRS 2008-Feb: to get around the OCTAL problem, introduced yy,mm,Myy,Mmm vars having a leading "10#" ==MAY NEED TESTING / DEBUGGING==??==