#!/usr/bin/env bash red="\033[1;31m" greenbold="\033[1;32m" green="\033[0;32m" yellow="\033[0;33m" bold="\033[1m" #bold_under="\033[1;4m" underline="\033[4m" reset="\033[0m" dir=$(dirname "$0") # /Users/bruno/Documents/Scripts/keywords2insta if [ ! -f ./birds.db ]; then cmd0="CREATE TABLE liste (Francais string, Fra string, Autres string, Aut string, Latin string, Anglais string, Ordre string, Famille string, Liens string);" echo "$cmd0" | sqlite3 ./birds.db if [ $? -ne 0 ]; then exit 0; fi fi array=() if [ -f "$dir"/Oiseaux_europe.csv ]; then # export Excel : CSV UTF-8 (délimité par des virgules) echo -e "Insertion des données du fichier .csv dans la base birds.db...\n" skip_headers=1 while IFS=';' read -ra array; do if ((skip_headers)); then # Ne pas lire le header ((skip_headers--)) else fr="${array[0]}" fr_wa="${array[1]}" aut="${array[2]}" aut_wa="${array[3]}" lat="${array[4]}" en="${array[5]}" or="${array[6]}" fa="${array[7]}" ln="${array[8]}" fr=$(echo "$fr" | sed "s/'/''/g") fr_wa=$(echo "$fr_wa" | sed "s/'/''/g") aut=$(echo "$aut" | sed "s/'/''/g") aut_wa=$(echo "$aut_wa" | sed "s/'/''/g") en=$(echo "$en" | sed "s/'/''/g") or=$(echo "$or" | sed "s/'/''/g") fa=$(echo "$fa" | sed "s/'/''/g") cmd1="INSERT INTO liste (Francais, Fra, Autres, Aut, Latin, Anglais, Ordre, Famille, Liens) VALUES ('$fr','$fr_wa','$aut','$aut_wa','$lat','$en','$or','$fa','$ln');" echo "$cmd1" | sqlite3 ./birds.db fi done < <(grep "" "$dir"/Oiseaux_europe.csv) # lit la dernière ligne même si elle n'est pas vide else echo -e "${red}No .csv file found !${reset}" exit 1 fi query="SELECT * FROM liste;" result=$(sqlite3 ./birds.db "$query") echo "$result"