#!/bin/bash

i=0
for arq in $(ls ./1?/*/00/profile*-000000-g1.ctl); do
    if [ ${i} -eq 0 ]; then
    echo ${arq%-A*}-template-g1.ctl
    
    fname=${arq#*00/}
    
    cat ${arq} | sed -e "s/${fname/ctl/gra}/${fname%-A*}-A-%y4-%m2-%d2-%h20000-g1.gra/g" \
    -e "/title oper/i options template" \
    -e "s/tdef   1 linear/tdef   9 linear/" > ${arq%-A*}-template-g1.ctl
    i=1
    else
    i=0
    fi
    
done 


exit 0
