GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Operating System  >  Shell Scripting
Go To First  |  Previous Question  |  Next Question 
 Shell Scripting  |  Question 37 of 47    Print  
How do you search the string for vowel's occurrence and number of occurrences of each vowel

  
Total Answers and Comments: 6 Last Update: June 05, 2009     Asked by: Nidhi2177 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: svaidehi
 
Even the below command can be used:

grep -io [aeiou] filename | wc -w

Above answer was rated as good by the following members:
jrgalaura
October 25, 2007 05:45:59   #1  
anuj.mmmec Member Since: October 2007   Contribution: 2    

RE: How do you search the string for vowel's occurrenc...
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'

 
Is this answer useful? Yes | No
October 25, 2007 05:57:37   #2  
anuj.mmmec Member Since: October 2007   Contribution: 2    

RE: How do you search the string for vowel's occurrenc...

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


 
Is this answer useful? Yes | No
April 10, 2008 03:22:01   #3  
svaidehi Member Since: April 2008   Contribution: 1    

RE: How do you search the string for vowel's occurrence and number of occurrences of each vowel
Even the below command can be used:

grep -io [aeiou] filename | wc -w

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
July 19, 2008 13:37:57   #4  
anu1985 Member Since: May 2008   Contribution: 11    

RE: How do you search the string for vowel's occurrence and number of occurrences of each vowel
tail -n +2 <file>|head -n 1
 
Is this answer useful? Yes | No
June 04, 2009 07:51:25   #5  
Rohit_Ash Member Since: May 2009   Contribution: 6    

RE: How do you search the string for vowel's occurrence and number of occurrences of each vowel
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

 
Is this answer useful? Yes | No
June 04, 2009 21:44:20   #6  
rana4bhu Member Since: June 2009   Contribution: 1    

RE: How do you search the string for vowel's occurrence and number of occurrences of each vowel
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....

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape