Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement