You are not logged in.

#1 2007-06-10 11:38:24

STUDENT
Member
Registered: 2007-06-10
Posts: 7

AWK help please - beginner

Hi, I'm in dire need of some help for AWK. I'm a college student and my statistics professor decided he'd teach AWK in the last two days of our class, even when it's not programming class and we don't even have computers in class to experiment. Anyway, I tried looking at AWK tutorials, but it doesn't necessarily teach me in the sequence our professor taught it. This is the code our professor wrote on the board for printing lines. I can't figure the thing out. If anyone can interpret it or correct me (if I miscopied the code), thank you.

Abe M 70
Bea F 65
Cathy F 67
Dave M 69

{if ($2 == "M"){
s=s+$3
n=n+1
}END{
print s, n, s/n, "avg height"
}

I have trouble understand the "s=s+$3" and "n=n+1" lines. What do those mean? Also, I have trouble understanding the "print" line. Obviously it means to print, but what would it print? "s" "n" and "s/n?" What is the "s/n" line?

Here's another one.

Abe M 70
Bea F 65
Cathy F 67
Dave M 69

{
if ($N / [fF] /) {
fsum = fsum + 3
fnum = fsum + 1
}
if ($2N/[mM]){
msum = msum + $3
mnum = mnum + 1
}
}

What does "if ($N / [fF] /)" or "($2N/[mM])" mean?

THX


I've studied HTML, Javascript and CSS in the past, and I like to know what each line or code does. I'm very OCD with programming, but it just frustrates me that the professor is simply teaching it this way WITHOUT (i repeat) a computer. This has got to be, by far, the most knuckleheaded professor I've probably taken in this college. Thx for the help.

Offline

#2 2007-06-10 11:41:54

.:B:.
Forum Fellow
Registered: 2006-11-26
Posts: 5,819
Website

Re: AWK help please - beginner

I don't think crossposting is allowed...


Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy

Offline

#3 2007-06-11 03:28:07

Snowman
Developer/Forum Fellow
From: Montreal, Canada
Registered: 2004-08-20
Posts: 5,212

Re: AWK help please - beginner

Yes. Locking.

Offline

Board footer

Powered by FluxBB