Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- convUtf="/tmp/convUtf.txt"
- padraoUnix="/tmp/padraoUnix.txt"
- usadoUnix="/tmp/usadoUnix.txt"
- resultado="/home/$USER/diferenca.txt"
- # Remove os Carriage Returns usado pelo windows.
- iconv --from-code=utf-16le --to-code=UTF-8 "$1" -o $convUtf
- tr -d \\r < $convUtf > $padraoUnix
- #tr -d \\r < $1 > $padraoUnix
- rm $convUtf
- iconv --from-code=utf-16le --to-code=UTF-8 "$2" -o $convUtf
- tr -d \\r < $convUtf > $usadoUnix
- #tr -d \\r < $2 > $usadoUnix
- rm $convUtf
- # Retira as linhas em branco repetidas para reduzir o tamanho
- # final do arquivo.
- sed -i "/^$/d" $padraoUnix
- sed -i "/^$/d" $usadoUnix
- declare -A registroPadrao=()
- while read linhaPadrao; do
- if [ "${linhaPadrao:0:1}" == "[" ]; then
- chavePadrao=${linhaPadrao#[}
- chavePadrao=${chavePadrao%]}
- chavePadrao=${chavePadrao//\\/.BARRA.}
- registroPadrao+=([$chavePadrao]="")
- else
- registroPadrao["$chavePadrao"]+="$linhaPadrao#;#"
- fi
- done < $padraoUnix
- declare -A registroUsado=()
- while read linhaUsada; do
- if [ "${linhaUsada:0:1}" == "[" ]; then
- chaveUsada=${linhaUsada#[}
- chaveUsada=${chaveUsada%]}
- chaveUsada=${chaveUsada//\\/.BARRA.}
- registroUsado+=([$chaveUsada]="")
- else
- registroUsado[$chaveUsada]+="$linhaUsada#;#"
- fi
- done < $usadoUnix
- for chave in "${!registroUsado[@]}"; do
- if [ -n "${registroPadrao[$chave]}" ]; then
- echo "$chave#;#${registroUsado[$chave]}" >> $resultado
- else
- if [ "${registroUsado[$chave]}" != "${registroPadrao[$chave]}" ]; then
- echo "$chave#;#${registroUsado[$chave]}" >> $resultado
- fi
- fi
- done
- exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement