1st commit
This commit is contained in:
54
insert.sh
Executable file
54
insert.sh
Executable file
@@ -0,0 +1,54 @@
|
||||
#!/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 ./apps.db ]; then
|
||||
cmd0="CREATE TABLE liste (Francais string, Autres string, Latin string, Anglais string, Liens string);"
|
||||
echo "$cmd0" | sqlite3 ./birds.db
|
||||
fi
|
||||
|
||||
array=()
|
||||
|
||||
if [ -f "$dir"/Oiseaux_europe.csv ]; then
|
||||
|
||||
skip_headers=1
|
||||
while IFS=';' read -ra array;
|
||||
do
|
||||
if ((skip_headers)); then # Ne pas lire le header
|
||||
((skip_headers--))
|
||||
else
|
||||
fr="${array[0]}"
|
||||
aut="${array[1]}"
|
||||
lat="${array[2]}"
|
||||
en="${array[3]}"
|
||||
ln="${array[4]}"
|
||||
|
||||
fr=$(echo "$fr" | sed "s/'/''/g")
|
||||
aut=$(echo "$aut" | sed "s/'/''/g")
|
||||
en=$(echo "$en" | sed "s/'/''/g")
|
||||
|
||||
cmd1="INSERT INTO liste (Francais, Autres, Latin, Anglais, Liens) VALUES ('$fr','$aut','$lat','$en','$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"
|
||||
Reference in New Issue
Block a user