Last active
April 29, 2021 14:59
-
-
Save cquest/1d3f42e50e001503c5b1481263571091 to your computer and use it in GitHub Desktop.
Script bash de récupération et conversion des fichiers Excel IRCOM en CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
ANNEE=$1 | |
mkdir -p $ANNEE | |
cd $ANNEE | |
# téléchargement des fichiers Excel | |
wget -N http://www2.impots.gouv.fr/documentation/statistiques/ircom$ANNEE/dep/{01..95}0.xls | |
wget -N http://www2.impots.gouv.fr/documentation/statistiques/ircom$ANNEE/dep/2A0.xls | |
wget -N http://www2.impots.gouv.fr/documentation/statistiques/ircom$ANNEE/dep/2B0.xls | |
wget -N http://www2.impots.gouv.fr/documentation/statistiques/ircom$ANNEE/dep/{971..976}.xls | |
# conversion et remise en cohérence des fichiers Excel en CSV | |
# changements de formats... | |
HEAD=26 | |
CUT=4 | |
if [ $ANNEE -gt 2010 ] | |
then | |
HEAD=23 | |
fi | |
if [ $ANNEE -gt 2016 ] | |
then | |
HEAD=19 | |
fi | |
if [ $ANNEE -gt 2018 ] | |
then | |
CUT=4,8,9 | |
fi | |
echo "dep,depcom,nom_commune,nb_foyers,revenu_fiscal_ref,impot_net,nb_foyers_imposables,revenu_fiscal_ref_foyers_imposables,nb_foyers_traitements_salaires,montant_traitements_salaires,nb_foyers_retraites_pensions,montant_retraites_pensions" > ../ircom$ANNEE.csv | |
for X in *.xls | |
do | |
CSV=D$(echo $X | sed 's/xls/csv/;s/0\./\./') | |
in2csv $X -K $HEAD -H -I | csvcut -C 1 | grep ',Total,' | csvcut -C $CUT \ | |
| sed 's/0,/,/;s/,n.d./,/g;s/,n.c./,/g;s/^\([0-9]*\),\([0-9]*\),/"\1"\,"\1\2",/;s/.0?,/,/;s/\.[0-9]*\?,/,/g;s/\.[0-9]*$//' \ | |
>> ../ircom$ANNEE.csv | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment