Hey Benny!
here you tell iconv to use utf8 source
That is because the source *IS* utf8.
I finetuned that a bit so that wc will count legitimate 8 bit characters that are not utf-8 as characters rather then bytes. It looks like this now;
iconv -f utf8 -t cp437 -c squirrels.utf8 | \
tr -d '\0-\177' | \
LC_ALL=C wc --chars
Note the LC_ALL=C setting will reset wc to count 8 bit characters as characters
on native utf-8 systems and won't hurt anything on actual 8 bit systems so it is perfectly safe to use even in scripts.
BTW if you change the cp437 to latin-1 you should get an error since of course there is no such alias as far as iconv is concerned. In fact you should get this output;
----- output for bogus latin-1 alias starts
iconv: conversion to `latin-1' is not supported
Try `iconv --help' or `iconv --usage' for more information.
0
----- output for bogus latin-1 alias ends
Of course latin1 will work as it should;
----- output for legitimate latin1 alias starts
1
----- output for legitimate latin1 alias ends
Not too many latin1 characters in that document given there are exactly 44 utf-8 characters.
Are you beginning to see the light?
Life is good,
Maurice
... Don't cry for me I have vi.
--- GNU bash, version 4.4.12(1)-release (x86_64-unknown-linux-gnu)
* Origin: Little Mikey's Brain - Ladysmith BC, Canada (1:153/7001)