-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencoding.sh
More file actions
executable file
·32 lines (22 loc) · 912 Bytes
/
Copy pathencoding.sh
File metadata and controls
executable file
·32 lines (22 loc) · 912 Bytes
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
#!/bin/bash
input_folder="${1:-.}"
utf="utf-8"
# Sans cela on a une erreur lorsqu'il n'y a pas de .txt par exemple, alors qu'on essaye juste de rester compatible avec les 2 formats.
shopt -s nullglob
for files in $input_folder/*.md $input_folder/*.txt
do
sed -i "s/\’/\'/g" $files #remplace les quotations marks en cp1252 par des apostrophes ce qui évite les problèmes réencodage cp1252>utf-8
sed -i "s/\œ/\oe/g" $files
sed -i "s/\—/\-/g" $files
sed -i "s/\ /\ /g" $files
sed -i "s/\–/\-/g" $files
encoding=$(file -i "$files" | sed "s/.*charset=\(.*\)$/\1/")
# -i display file's encoding
# sed is a stream editor that enables you to modify text
# the rest, idk
if [ ! "$utf" == "${encoding}" ] # if the encoding is != from utf-8
then
echo "recoding from ${encoding} to $utf file : $files" #debug
recode ${encoding}..$utf $files #recode file with the utf-8 encoding
fi
done