diff --git a/fio_splitter.sh b/fio_splitter.sh index ba29be9..b8b7063 100644 --- a/fio_splitter.sh +++ b/fio_splitter.sh @@ -101,8 +101,66 @@ log() { echo `date '+%Y-%m-%d %H:%M:%S'` "$@" } +# +# Gets only given header +# $1 - path to file +# $2 - header name +get_header_field() { + grep "^$2" "$1" +} +# +# Splits given file into twelve months +split_year() { + # Examine name + CSVNAME="$1" + bname=${CSVNAME##*/} + ACCNO=${bname%%-*} + rest=${bname##*-} + YEAR=${rest%%.*} + log Splitting "$CSVNAME" year "$YEAR" account "$ACCNO" + + # Read header + accountId=`get_header_field $CSVNAME accountId` + bankId=`get_header_field $CSVNAME bankId` + currency=`get_header_field $CSVNAME currency` + iban=`get_header_field $CSVNAME iban` + openingBalance=`get_header_field $CSVNAME openingBalance` + closingBalance=`get_header_field $CSVNAME closingBalance` + dateStart=`get_header_field $CSVNAME dateStart` + dateEnd=`get_header_field $CSVNAME dateEnd` + idFrom=`get_header_field $CSVNAME idFrom` + idTo=`get_header_field $CSVNAME idTo` + + # Emit months + for month in `seq 1 12` ; do + MONTH=$month + if [ $MONTH -lt 10 ] ; then + MONTH=0$MONTH + fi + MCSVNAME="$BANK_DIR_PARTS/$ACCNO-$YEAR-$MONTH.csv" + log $MCSVNAME + done +} + +# Current year (last in seq) +CYEAR=`date +%Y` + +# Process all known accounts log Started while read accnt ; do - log $accnt -done + # Extract account number and starting year + ACCNO=${accnt%% *} + accrest=${accnt#* } + accrest2=${accrest#* } + YEAR=${accrest2%% *} + + # Process the account + log ==== ACCNO=$ACCNO YEAR=$YEAR + + # Iterate over years + for year in `seq $YEAR $CYEAR` ; do + CSVNAME="$BANK_DIR_PARTS/$ACCNO-$year.csv" + split_year $CSVNAME + done +done < "$APIKEYS_FILE"