![]() |
|
|||||||
| Programming C, bash, Python, Perl, PHP, Java, you name it. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|||
|
Hi guys,
I use nmh for my mail; plain text mails are displayed with less(1). Unfortunately, since my xterm uses UTF-8 by default, any ISO8859 mails will tend to have �’s everywhere. I thought I’d fix this by piping output through a simple script first: Code:
#!/bin/sh
while read input
do
echo $input | file - | grep 8859 > /dev/null
if [[ $? = 0 ]]; then
echo $input | iconv -f ISO-8859-1 -t UTF-8
else
echo $input
fi
done
Code:
$ time u8conv.sh < /etc/hosts >/dev/null
0m0.22s real 0m0.11s user 0m0.11s system
$ time cat /etc/hosts >/dev/null
0m0.00s real 0m0.00s user 0m0.00s system
__________________
Many thanks to the forum regulars who put time and effort into helping others solve their problems. |
|
|||
|
Tried this, it was much faster, thanks. The mail is already saved to a temporary file, so this is easy.
Code:
#!/bin/sh
file $1 | grep 8859 > /dev/null
if [[ $? = 0 ]]; then
iconv -f ISO-8859-1 -t UTF-8 < $1
else
cat $1
fi
__________________
Many thanks to the forum regulars who put time and effort into helping others solve their problems. |
|
||||
|
Since your case is already solved, I'll just leave a note for the next person to find it.
If you're processing a stream line by line with a while read loop in sh script, you're probably doing it wrong.
__________________
My Journal Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ask for a shell script | Simon | Programming | 5 | 27th April 2010 01:07 AM |
| shell script compare md5 sum | bsdnewbie999 | Programming | 1 | 11th April 2009 02:20 PM |
| incrementing within a shell script? | spiderpig | Programming | 5 | 29th September 2008 08:12 PM |
| Shell Script. | bsdnewbie999 | Programming | 21 | 15th July 2008 07:54 AM |
| shell script with input | c0mrade | Programming | 5 | 13th July 2008 04:33 AM |