#!/bin/bash

### Want to create 56 scripts to cover 1000 souces each from 0 to 55880
### (Final script just does 880)

### Template file is bsnrj_rev_template.py 
### Just need to modify OUTPUTFILE, STARTNUMBER, ENDNUMBER

for i in {1..56}
do
    SCRIPTNUMBER=$((i))
    STARTNUMBERSTRING=$(((i-1)*1000))
    ENDNUMBERSTRING=$(($STARTNUMBERSTRING+1000))

    if [ $SCRIPTNUMBER = 1 ]; then
      STARTNUMBERSTRING=1
    fi

    if [ $SCRIPTNUMBER = 56 ]; then
      ENDNUMBERSTRING=55881
    fi

    OUTPUTFILESTRING='joint-'$SCRIPTNUMBER'.csv'

#    echo "$SCRIPTNUMBER $STARTNUMBERSTRING $ENDNUMBERSTRING $OUTPUTFILESTRING"

    echo "Creating script $SCRIPTNUMBER"
    rm bsnrj-$SCRIPTNUMBER.py
    cp bsnrj_rev_template.py bsnrj-$SCRIPTNUMBER.py 

    sed -i 's/OUTPUTFILE/'$OUTPUTFILESTRING'/g' bsnrj-$SCRIPTNUMBER.py
    sed -i 's/STARTNUMBER/'$STARTNUMBERSTRING'/g' bsnrj-$SCRIPTNUMBER.py
    sed -i 's/ENDNUMBER/'$ENDNUMBERSTRING'/g' bsnrj-$SCRIPTNUMBER.py

done
