Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting 'vowel' out of my output

Status
Not open for further replies.

Simmy

Technical User
Sep 7, 2002
27
GB
Question:
My input looks like this:
VOWEL,OPENING,PLACE,ENVIRONMENT.
U,3,2,C.
I,3,2,S.
...
I want to count the different vowels but 'VOWEL' itself may not be in the output.
I had this script:
BEGIN {
FS=","
}
{
vowels [$1]++
}
END {
delete vowels[vowel]
for (vowel in vowels)
printf("%s\t%d\n", vowel, vowels[vowel])
}
Why is 'VOWEL' still in my output?
How can I solve this problem?
 
simmy,

When I run your script, I get
Code:
I   1
U   1
as expected. What output you want?
BTW, the statement
Code:
delete vowels[vowel]
is trying to delete non-existant element 0 from the vowels array and is unnecessary.

Hope this helps. CaKiwi
 
CaKiwi,

Yes, your output is what I want but mine is still:

U 1
I 1
VOWEL 1

My script takes the first field of my input as a vowel, doesn't it?
 
What about this ...

BEGIN {
FS=","
}

$1 != "VOWEL" {vowels [$1]++}

END {
delete vowels[vowel]
for (vowel in vowels)
printf("%s\t%d\n", vowel, vowels[vowel])
}

Greg.
 
I somehow completely missed the line
VOWEL,OPENING,PLACE,ENVIRONMENT.
in your input despite the fact that it was capitalized. :~/. Grega's solution looks good, but it seems to me that the delete line is still superfluous. CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top