-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconvert_text_error_to_UTF8_JBs.sh
More file actions
executable file
·107 lines (93 loc) · 2.53 KB
/
Copy pathconvert_text_error_to_UTF8_JBs.sh
File metadata and controls
executable file
·107 lines (93 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
#
# Autor= João Batista Ribeiro
# Bugs, Agradecimentos, Críticas "construtivas"
# me envie um e-mail. Ficarei Grato!
# e-mail: joao42lbatista@gmail.com
#
# Este programa é um software livre; você pode redistribui-lo e/ou
# modifica-lo dentro dos termos da Licença Pública Geral GNU como
# publicada pela Fundação do Software Livre (FSF); na versão 2 da
# Licença, ou (na sua opinião) qualquer versão.
#
# Este programa é distribuído na esperança que possa ser útil,
# mas SEM NENHUMA GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a
# qualquer MERCADO ou APLICAÇÃO EM PARTICULAR.
#
# Veja a Licença Pública Geral GNU para mais detalhes.
# Você deve ter recebido uma cópia da Licença Pública Geral GNU
# junto com este programa, se não, escreva para a Fundação do Software
#
# Livre(FSF) Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# Script: Convert common errors from ISO-8859-1 (ISO Latin 1) accents to UTF-8
#
# Last update: 19/06/2023
#
# Online: https://onlineutf8tools.com/convert-ascii-to-utf8
#
# More information:
# https://berseck.wordpress.com/2010/09/28/transformar-utf-8-para-acentos-iso-com-php/comment-page-1/
# https://wallacesilva.com/blog/2016/12/converter-para-utf-8-caracteres-iso-em-php/
# https://www.i18nqa.com/debug/utf8-debug.html
#
fileName=$1
if [ "$fileName" == '' ]; then
echo -e "\nError: Need to test if pass file as parameter to work\n"
exit 1
fi
codification=$(file "$fileName") # Get the codification of the file
if echo "$codification" | grep -q "UTF-8"; then # Check if codification is UTF-8
fileNameTmp=$(echo "$fileName" | rev | cut -d "." -f2- | rev)
fileExtension=$(echo "$fileName" | rev | cut -d "." -f1 | rev)
cat "$fileName" | sed '
s/á/á/g
s/Ã /à/g
s/â/â/g
s/ã/ã/g
s/ä/ä/g
s/é/é/g
s/è/è/g
s/ê/ê/g
s/ë/ë/g
s/Ã/í/g
s/ì/ì/g
s/î/î/g
s/ï/ï/g
s/ó/ó/g
s/ò/ò/g
s/ô/ô/g
s/õ/õ/g
s/ö/ö/g
s/ú/ú/g
s/ù/ù/g
s/û/û/g
s/ü/ü/g
s/ç/ç/g
s/Ã/Á/g
s/À/À/g
s/Â/Â/g
s/Ã/Ã/g
s/Ä/Ä/g
s/É/É/g
s/È/È/g
s/Ê/Ê/g
s/Ë/Ë/g
s/Ã/Í/g
s/ÃŒ/Ì/g
s/ÃŽ/Î/g
s/Ã/Ï/g
s/Ó/Ó/g
s/Ã’/Ò/g
s/Ô/Ô/g
s/Õ/Õ/g
s/Ö/Ö/g
s/Ú/Ú/g
s/Ù/Ù/g
s/Û/Û/g
s/Ü/Ü/g
s/Ç/Ç/g' > "${fileNameTmp}_c.$fileExtension"
echo -e "\nFile converted: ${fileNameTmp}_c.$fileExtension\n"
else
echo -e "\nError: The file \"$fileName\" don't has codification UTF-8, first convert it to UTF-8 with \"codific_JBs.sh\" \"$fileName\"\n"
fi