Number of Vowels


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Number of Vowels
# 8  
Old 09-13-2006
ok here is one more
Code:
grep "[aeiouAEIOU]" filename.txt | tr -cd 'aeiouAEIOU' | wc -c

# 9  
Old 09-13-2006
I am not sure whether u want the total count or the count of 'A', 'E', 'I', 'O' and 'U' separately.
However the one-liner that I have given will give separate counts.

First, the command
Code:
tr '[a-z]' '[A-Z]' < 1.txt

will convert the contents of 1.txt to capital letters. Then, the command
Code:
tr -sc 'AEIOU' '[\012*]'

will tokenize the contents of the file to give only vowels.

On this output you are sorting so that you could use the uniq command on it.
uniq -c will precede each output line with the count of the number of times the line occurred in the input.
# 10  
Old 09-13-2006
Some alternatives...
Code:
$ fold -1 input.txt|egrep -i '[aeiou]'|sort |uniq -c
     14 a
     11 e
      6 i
      8 o
      3 u
$ tr -dc AEIOUaeiou < input.txt | fold -1 | sort |uniq -c
     14 a
     11 e
      6 i
      8 o
      3 u
$ fold -1 input.txt|egrep -ic '[aeiou]'
42
$ tr -dc AEIOUaeiou < input.txt | wc -c
     42

# 11  
Old 09-13-2006
MySQL Thanks a ton

Hi All,

Thanks for such quick and amazing responses.
Thanks a lot.
Maybe I need to explore the power of tr command.

Thanks and Regards,
Gaurav Goel
# 12  
Old 09-12-2008
PHP :-(

Quote:
Originally Posted by charu
This is one way of achieving the count of vowels in the file 1.txt

Code:
tr '[a-z]' '[A-Z]' < 1.txt | tr -sc 'AEIOU' '[\012*]' | sort | uniq -c



well.. this wont work in every case..
let's suppose 1.txt is like this:
Code:
$ cat 1.txt
aaaa

The output is :
Code:
$ tr '[a-z]' '[A-Z]' < 1.txt | tr -sc 'AEIOU' '[\012*]' | sort | uinq -c
   1 AAAA

which is wrong.. as there are four vowels Smilie

as there is nothing else to replace the new line character with...
the repetitive characters are counted as 1
# 13  
Old 09-12-2008
Code:
awk '{
 for(i=1;i<=NF;i++)
 if($i=="vowels")
 n++
 }
END{
print n
}' file

# 14  
Old 09-28-2008
Quote:
Originally Posted by Ygor
Some alternatives...
Code:
$ fold -1 input.txt|egrep -i '[aeiou]'|sort |uniq -c
     14 a
     11 e
      6 i
      8 o
      3 u
$ tr -dc AEIOUaeiou < input.txt | fold -1 | sort |uniq -c
     14 a
     11 e
      6 i
      8 o
      3 u
$ fold -1 input.txt|egrep -ic '[aeiou]'
42
$ tr -dc AEIOUaeiou < input.txt | wc -c
     42

fold is another useful command... Thanks Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Pure C function pointer on printing vowels twice

Have difficulty to understand this pure C code to only print vowels twice from input string. Questions are commented at the end of each place. #include <stdio.h> #include <stdlib.h> #include <assert.h> #include <limits.h> /* *Demonstrate the use of dispatch tables */ /*Print a char... (11 Replies)
Discussion started by: yifangt
11 Replies

2. Shell Programming and Scripting

awk to find number in a field then print the line and the number

Hi I want to use awk to match where field 3 contains a number within string - then print the line and just the number as a new field. The source file is pipe delimited and looks something like 1|net|ABC Letr1|1530||| 1|net|EXP_1040 ABC|1121||| 1|net|EXP_TG1224|1122||| 1|net|R_North|1123|||... (5 Replies)
Discussion started by: Mudshark
5 Replies

3. Shell Programming and Scripting

Help with sort word followed by exponential number and numeric number at the same time

Input file: ID_34 2E-69 2324 ID_1 0E0 3254 ID_1 0E0 5434 ID_5 0E0 436 ID_1 1E-14 2524 ID_1 5E-52 46437 ID_3 65E-20 45467 ID_1 0E0 6578 ... Desired output file: ID_1 0E0 6578 ID_1 0E0 5434 ID_1 0E0 3254 ID_1 5E-52 46437 ID_1 1E-14 2524 ID_3 65E-20 45467 (5 Replies)
Discussion started by: cpp_beginner
5 Replies

4. UNIX for Dummies Questions & Answers

Grepping Words with No Vowels

Hi! I was trying to grep all the words in a wordlist, (twl), with no vowels. I had a hard time figuring out how to do it, but I finally lit on the -v flag. Here's my question: Why does this work: grep -v '' twl But this doesn't: grep '' twl In the second example, we're asking for lines... (6 Replies)
Discussion started by: sudon't
6 Replies

5. Shell Programming and Scripting

The difference between end number in the early row and the start number in the next

Hi Power User, I'm trying to compute this kind of text file format: file1: jakarta 100 150 jakarta 170 210 beijing 220 250 beijing 260 280 beijing 290 320 new_york 330 350 new_york 370 420 tokyo 430 470 tokyo 480 ... (2 Replies)
Discussion started by: anjas
2 Replies

6. Shell Programming and Scripting

AWK print number of records, divide this number

I would like to print the number of records of 2 files, and divide the two numbers awk '{print NR}' file1 > output1 awk '{print NR}' file2 > output2 paste output1 output2 > output awl '{print $1/$2}' output > output_2 is there a faster way? (8 Replies)
Discussion started by: programmerc
8 Replies

7. Shell Programming and Scripting

Perl : print the sequence number without missing number

Dear Perl users, I need your help to solve my problem below. I want to print the sequence number without missing number within the range. E.g. my sequence number : 1 2 3 4 5 6 7 8 11 12 13 14 my desired output: 1 -8 , 11-14 my code below but still problem with the result: 1 - 14 1 -... (2 Replies)
Discussion started by: mandai
2 Replies

8. UNIX for Dummies Questions & Answers

Counting vowels in string. "Comparison pointer-integer".

I'm trying to write a programme which scans strings to find how many vowels they contain. I get an error saying that I'm trying to compare a pointer and an integer inif(*v == scanme){. How can I overcome this ? Also, the programme seems to scan only the first word of a string e.g.: if I type "abc... (1 Reply)
Discussion started by: fakuse
1 Replies

9. Shell Programming and Scripting

Number lines of file and assign variable to each number

I have a file with a list of config files numbered on the lefthand side 1-300. I need to have bash read each lines number and assign it to a variable so it can be chosen by the user called by the script later. Ex. 1 some data 2 something else 3 more stuff which number do you... (1 Reply)
Discussion started by: glev2005
1 Replies
Login or Register to Ask a Question