🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #3975

Re: shell programming help

#3975
From: Walter T Rejuney
Date: Wed, 11 Oct 2000 00:00
62 lines
2121 bytes
thaboyz wrote:

> i wrote a program that replaces percentages to their equivalent letter
> grade.
>
> my file looks like this
>
> 34 56 98 23 90 87
> 34 52 87 65 99 34
>
> i need the output to look like this
>
> F D A F A A
> F D A C A F
>
> when i echo the display it shows like this on the screen
>
> F D A F A A F D A C A F
>
> i want it to display
>
> F D A F A A
> F D A C A F

#!/bin/ksh
typeset -r Infile='mydata.dat';
typeset -r Outfile='grades.txt';
function Printit {
    print -u4 "${1} \c";
}
exec 3<${Infile};
if [[ $? -ne 0 ]];then
    print -u2 "Unable to open ${Infile} for reading";
    exit 1;
fi
exec 4>${Outfile};
if [[ $? -ne 0 ]];then
    print -u2 "Unable to open ${Outfile} for writing";
    exit 1;
fi
IFS=' ';
while read -u3 Buff;do
    if [[ ${#Buff} -lt 1 ]];then
        continue;
    fi;
    for i in ${Buff};do
        if [[ ${i} -lt 40 ]];then
            Printit "F";
        elif [[ ${i} -lt 60 ]];then
            Printit "D";
        elif [[ ${i} -lt 70 ]];then
            Printit "C";
        elif [[ ${i} -lt 80 ]];then
            Printit "B";
        else
            Printit "A";
        fi
    done;
    print -u4 "";
done
print -u2 "Run complete";
exec 3<&-;
Technical Details
Message-ID: <39E4698B.8FA70982@Unforgetable.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <s4xC5.314094$1h3.7559966@news20.bellglobal.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fe8ab,79a93a9b97f9cd1a
X-Google-Attributes: gidfe8ab,public
X-Google-Thread: faae6,79a93a9b97f9cd1a
X-Google-Attributes: gidfaae6,public
X-Google-Thread: 1006bb,79a93a9b97f9cd1a
X-Google-Attributes: gid1006bb,public
X-Google-Thread: 1012a6,79a93a9b97f9cd1a
X-Google-Attributes: gid1012a6,public
From: Walter T Rejuney <BlueSax@Unforgetable.com>
Subject: Re: shell programming help
Date: 2000/10/11
Message-ID: <39E4698B.8FA70982@Unforgetable.com>
X-Deja-AN: 680133724
Content-Transfer-Encoding: 7bit
References: <s4xC5.314094$1h3.7559966@news20.bellglobal.com>
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
Organization: xyzzy
Mime-Version: 1.0
Reply-To: BlueSax@Unforgetable.com
Newsgroups: comp.unix.shell,comp.unix.shells,fj.questions.unix,man.unix.help