View Single Post
  #1   (View Single Post)  
Old 18th July 2010
backrow backrow is offline
Real Name: Anthony J. Bentley
Shell Scout
 
Join Date: Jul 2009
Location: Albuquerque, NM
Posts: 136
Default Can I make this shell script faster?

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
This works, but makes reading my mail noticeably slower:
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
Is there an obvious way to make the script faster? Perhaps there’s a better way to solve my problem that I’ve missed.
__________________
Many thanks to the forum regulars who put time and effort into helping others solve their problems.
Reply With Quote