#!/bin/bash

sed -i "s/\"/ /g" $1 

if [[ $2 == "cal" ]]
then
echo "strutr;r0cmp;r0gir;r0gio;r0anr;r0dai;r0ma1;r0ma2;r0no1;r0pu1;r0pu2;void1;void2;void3;void4;void5;void6;void7;r0imp;r0ori;void8"|cat - $1   > /tmp/out && mv /tmp/out $1"_int"
fi


if [[ $2 == "imp" ]]
then
echo "i0str;i0imp;i0dei;i0ini;i0loi;i0prv;void"|cat - $1   > /tmp/out && mv /tmp/out $1"_int"
fi

if [[ $2 == "ana" ]]
then
echo "SCOSO;SCOMO;SCOMI;SCOMC;SCOMF;SSIGL;SDENO;DESCA;X21;X23;X24;SPC01;SIND1;SIND2;SCAPS;SLOCR;SPVRE;SINC1;SINC2;SCAPC;SLOCO;SPVCO;STEDS;STEPR;STESR;SCAPO;SFAXS;STELX;SPIVA;SNATU;SSITO;SMAIL;SPRESC;SPRESN;F0DEI;F0INI;F0LOI;F9COI;F0PRV;F0CAP;C0DEI;C0INI;C0LOI;C9COI;C0PRV;C0CAP;D0DEI;D0INI;D0LOI;D9COI;D0PRV;D0CAP;SAT01;SAT02;SAT03;SAT04;SAT05;SAT06;SAT07;SAT08;SAT09;SAT10;void"|cat - $1   > /tmp/out && mv /tmp/out $1"_int"
fi

if  [[ $2 == "cla" ]]
then
echo "REG;KSGTCL;GIRONE;IDSOC;PUNTI;GF;GS;GIOCATE;VINTE;PAREGGIATE;perse"|cat - $1   > /tmp/out && mv /tmp/out $1"_int"
fi



iconv -f iso-8859-1 -t UTF-8 $1"_int" -o  $1"_int_utf8"
sed '1s/^\xEF\xBB\xBF//' < $1"_int_utf8"  >$1"_int_utf8_nobom.csv"
sed -i '1s/^\xEF\xBB\xBF//' $1"_int_utf8"