How do you search the string for vowel's occurrence and number of occurrences of each vowel

Questions by Nidhi2177

Showing Answers 1 - 7 of 7 Answers

anuj.mmmec

  • Oct 25th, 2007
 

for a=cat filename |tr -d 'eioubcdfghjklmnpqrstvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890()~`!@#$%^&*"()_+{}|:"<>?,./;][=-/n ' |grep a|wc -m
for e=cat filename |tr -d 'aioubcdfghjklmnpqrstvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890()~`!@#$%^&*"()_+{}|:"<>?,./;][=-/n ' |grep e|wc -m
for i=cat filename |tr -d 'aeoubcdfghjklmnpqrstvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890()~`!@#$%^&*"()_+{}|:"<>?,./;][=-/n ' |grep i|wc -m
for o=cat filename |tr -d 'aeiubcdfghjklmnpqrstvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890()~`!@#$%^&*"()_+{}|:"<>?,./;][=-/n ' |grep o|wc -m
for u=cat filename |tr -d 'aeiobcdfghjklmnpqrstvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890()~`!@#$%^&*"()_+{}|:"<>?,./;][=-/n ' |grep u|wc -m


it will give the no of time that vowel has been occured


for searching the string
cat filename | grep 'aeiou'

  Was this answer useful?  Yes

anuj.mmmec

  • Oct 25th, 2007
 

hey please also add           tr -d '        before wc -m

FE : cat filename|tr -d 'eioubcdfghjklmnpqrstvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890()~`!@#$%^&*"()_+{}|:"<>?,./;][=-/n ' |grep a|tr -d '|wc -m


for counting the vowels

  Was this answer useful?  Yes

Rohit_Ash

  • Jun 4th, 2009
 

For 'a'
cat file_name | tr -cd 'a' | wc -m

For 'e'
cat file_name | tr -cd 'e' | wc -m

For 'i'
cat file_name | tr -cd 'i' | wc -m

For 'o'
cat file_name | tr -cd 'o' | wc -m

For 'u'
cat file_name | tr -cd 'u' | wc -m

rana4bhu

  • Jun 4th, 2009
 

I am giving the 3 ways to solve this problem..

1) grep -io "[aeiouAEIOU]" filename | sort | uniq -c

2) cat filename | sed 's/[a-zA-Z]/&n/g' | sed 's/^ //' | grep "[aeiouAEIOU]" | sort | uniq -c

3) cat filename | fold -1 | sort | sed -n '/^[aeiouAEIOU]/p' | uniq -c

Thanks
All codes are tested and working....

anil

  • Sep 21st, 2017
 

upendram@upendrams-host:~$ echo $pattern | grep -o . | while read chars; do cnt=`echo "${str}" | grep -o "${chars}" | wc -l`; if [[ $cnt -gt 0 ]]; then echo "$chars -- occurs --- $cnt times" >> string_counts; fi; done
upendram@upendrams-host:~$ cat string_counts
e -- occurs --- 3 times
i -- occurs --- 3 times
o -- occurs --- 1 times
u -- occurs --- 1 times
upendram@upendrams-host:~$ echo $str
Thuis is some text file
upendram@upendrams-host:~$ echo $pattern
aAeEiIoOuU

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.