#!/bin/bash
# Creditos:
# Amilcar de Jesus Moreti
# AJM SOLUTIONS
# amilcar@ajmsolutions.com.br
#
# Ronaldo Guizo
# PAINCO
# ronaldo@paico.com.br
#
# Local:
# /usr/local/bin/clean2.sh
#
# Script desenvolvido para realizar alteracao em arquivos textos
# que contenham codificação Hexa;
#
# Data Criacao = 28/03/2017 - Data Modificacao = 01/04/2017
#
# Versao = 1 - Release = 03
#
#-----------------------------------------------------------
# . . #
# . .:::. #
# :(o o): . #
#ooO--(_)--Ooo---------BY __ #
# _ '_ ( / _/' _ #
# (////) __)()((///()/)_) #
# _/ #
#-----------------------------------------------------------
# Variaveis Ambiente
dirUnl="/archive/dbExport/logix.exp"
codHex="bd be 80 81 82 83 86 87 92 93 94 95 96 8d 8e 9a 9d"
fileSol="$dirUnl/solucao.txt"
fileFinal="$dirUnl/arqCorreto.txt"
extFile="*.unl"
cat /dev/null > $fileSol
cd $dirUnl
for i in ${codHex}
do
echo "Procurando pelo codigo Hexa $i"
grep -P -n "\x$i" $extFile |awk -F: '{print $1, $2}' |uniq >> $fileSol 2> /dev/null
done
cat $fileSol |sort -o $fileSol
cat $fileSol |uniq > $fileFinal
for x in $(cat $fileFinal | awk '{print $1}' | uniq)
do
for line in $(cat $fileFinal |grep $x | awk '{print $2}')
do
echo "Alterando a linha $line do arquivo $x"
sed -i ''$line's/.\xbd/I/g' $x
sed -i ''$line's/.\xbe/I/g' $x
sed -i ''$line's/.\x8d/I/g' $x
sed -i ''$line's/.\x8e/A/g' $x
sed -i ''$line's/.\x80/C/g' $x
sed -i ''$line's/.\x81//g' $x
sed -i ''$line's/.\x82/e/g' $x
sed -i ''$line's/.\x83/a/g' $x
sed -i ''$line's/.\x86//g' $x
sed -i ''$line's/.\x87/C/g' $x
sed -i ''$line's/.\x9a/U/g' $x
sed -i ''$line's/.\x9d/C/g' $x
sed -i ''$line's/.\x92//g' $x
sed -i ''$line's/.\x93/"/g' $x
sed -i ''$line's/.\x94/"/g' $x
sed -i ''$line's/.\x95//g' $x
sed -i ''$line's/.\x96/-/g' $x
echo ""
done
done