2013-03-03 00:01:20 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
2013-10-23 17:44:23 +02:00
|
|
|
if [ $# -eq 0 ] || [ "$1" = "-h" ]; then
|
2014-11-12 16:15:39 +01:00
|
|
|
cat<<EOF
|
2015-09-12 15:10:51 +02:00
|
|
|
Usage: ${0##*/} FOLDERS
|
2013-10-23 17:44:23 +02:00
|
|
|
|
|
|
|
Convert all 'bad' encoding to UTF-8/LF.
|
|
|
|
|
|
|
|
WARNING: It will fail for encodings other the one explicitly supported below.
|
|
|
|
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
|
2014-08-19 11:06:03 +02:00
|
|
|
if ! command -v recode >/dev/null 2>&1; then
|
2014-11-12 16:15:39 +01:00
|
|
|
echo "recode needed."
|
|
|
|
exit
|
2013-03-03 00:01:20 +01:00
|
|
|
fi
|
|
|
|
|
2013-10-23 17:44:23 +02:00
|
|
|
for i ; do
|
2014-11-12 16:15:39 +01:00
|
|
|
while IFS= read -r j; do
|
|
|
|
CODING=$(file "$j")
|
|
|
|
|
2016-06-23 23:18:36 +02:00
|
|
|
case "$CODING" in
|
|
|
|
*ISO-8859*)
|
2014-11-12 16:15:39 +01:00
|
|
|
echo "ISO-8859: [$j]"
|
2016-06-23 23:18:36 +02:00
|
|
|
recode latin1..utf-8 "$j";;
|
|
|
|
*'Non-ISO extended-ASCII'*)
|
2014-11-12 16:15:39 +01:00
|
|
|
echo "cp1252: [$j]"
|
2016-06-23 23:18:36 +02:00
|
|
|
recode cp1252..utf-8 "$j";;
|
|
|
|
*'UTF-16 Unicode text'*)
|
2014-11-12 16:15:39 +01:00
|
|
|
echo "UTF-16: [$j]"
|
2016-06-23 23:18:36 +02:00
|
|
|
recode utf-16..utf-8 "$j";;
|
|
|
|
*'UTF-8 Unicode (with BOM)'*)
|
2014-11-12 16:15:39 +01:00
|
|
|
echo "UTF-8 BOM: [$j]"
|
2016-06-23 23:18:36 +02:00
|
|
|
ex -sc '1s/^.//|xit' "$j";;
|
2014-11-12 16:15:39 +01:00
|
|
|
## The following commands are funny alternatives, but are completely
|
|
|
|
## overkill.
|
|
|
|
# dd iflag=skip_bytes skip=3 if=file.srt of=temp.srt
|
|
|
|
# dd bs=1 skip=3 if=file.srt of=temp.srt
|
|
|
|
# tail -c +32 file.srt > temp.srt
|
2016-06-23 23:18:36 +02:00
|
|
|
esac
|
2014-11-12 16:15:39 +01:00
|
|
|
|
2016-06-23 23:18:36 +02:00
|
|
|
if echo "$CODING" | grep -q 'CRLF'; then
|
2014-11-12 16:15:39 +01:00
|
|
|
echo "CRLF: [$j]"
|
|
|
|
ex -sc '%s/
//g|xit' "$j"
|
|
|
|
fi
|
|
|
|
|
|
|
|
done <<EOF
|
2013-10-23 17:44:23 +02:00
|
|
|
$(find "$i" -type f -size -50M -print)
|
2013-03-03 00:01:20 +01:00
|
|
|
EOF
|
2013-10-23 17:44:23 +02:00
|
|
|
done
|