-
-
Save franklinbr/d3caf1917776ad9a3513b6fa8e286987 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
arquivo_entrada='script.sql' | |
arquivo_tmp='temporario.sql' | |
arquivo_saida='saida.sql' | |
function AjustesIniciais() { | |
head -n1 ${arquivo_entrada} | tail -n1 > ${arquivo_tmp} | |
echo "" >> ${arquivo_tmp} | |
head -n3 ${arquivo_entrada} | tail -n1 | sed 's/\$/variavel/g' >> ${arquivo_tmp} | |
} | |
function AplicaValores() { | |
local query=$(head -n3 ${arquivo_tmp} | tail -n1) | |
local parametro_linha=$(head -n1 ${arquivo_tmp} | tail -n1) | |
local parametro=$(echo $parametro_linha | tr "," "\n" | cut -d= -f2 | sed 's/ //') | |
IFS=' | |
' | |
local incrementoj=0 | |
local vetor=() | |
for argumento in $parametro | |
do | |
vetor[$incrementoj]=$argumento | |
let incrementoj++ | |
done | |
local incrementoj=1 | |
local query_cache="" | |
for i in ${vetor[@]} | |
do | |
query=$(echo $query | sed "s/\<variavel${incrementoj}\>/$i/g") | |
query_cache=$query | |
let incrementoj++ | |
done | |
echo $query >> ${arquivo_saida} | |
# adiciona ; no final de cada linha | |
sed -i 's/$/;/g' ${arquivo_saida} | |
# deleta arquivo temporario | |
if [ -f "$arquivo_tmp" ] | |
then | |
rm ${arquivo_tmp} | |
fi | |
} | |
AjustesIniciais | |
AplicaValores |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment