Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #cat alunos.txt
- #Nome;turma;periodo
- #Zé das cove;a2;matutino
- #Tião;d3;vespertino
- #Mariazinha;w1;matutino
- #Leo;k9;noturno
- jsonObjPatern="{"$(head -n 1 alunos.txt | sed 's/[;]/,/g')"}"
- IFS=";" read -ra fields <<< "$(head -n 1 alunos.txt)"
- numberOfElements=${#fields[@]}
- while read csvLine; do
- IFS=";" read -ra values <<< $(echo $csvLine)
- asdfgh=0
- obj=$jsonObjPatern
- while [ ${asdfgh:-0} -lt ${numberOfElements:-0} ]; do
- qwerty=${fields[$asdfgh]}
- zxcvbn=${fields[$asdfgh]}":"${values[$asdfgh]}
- obj=${obj/$qwerty/$zxcvbn}
- asdfgh=$(($asdfgh+1))
- done
- jsonObj=$jsonObj$obj","
- done <<< $(cat alunos.txt | sed -n '1!p')
- echo $jsonObj
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement