Computing.Net > Forums > Unix > shell script for string search

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

shell script for string search

Reply to Message Icon

Original Message
Name: Bjorn
Date: August 20, 2003 at 10:54:57 Pacific
Subject: shell script for string search
OS: Unix
CPU/Ram: P4
Comment:

Hi

I have to write a shell script to accept a string, check for vowels and display it on screen.

How do i write it? Thanks

--bs.



Report Offensive Message For Removal


Response Number 1
Name: David Perry
Date: August 20, 2003 at 12:47:30 Pacific
Reply: (edit)

Please post what you've done so far with questions about the trouble spots and someone would be glad to help you.


Report Offensive Follow Up For Removal

Response Number 2
Name: Frank
Date: August 21, 2003 at 04:26:42 Pacific
Reply: (edit)

Try:

#!/bin/ksh
typeset -i x=1

read string?"please Enter String:"
Char=`echo $string | cut -c ${x}-${x} `

while [ -n "${Char}" ]
do
case ${Char} in
a|A|e|E|i|I|o|O|u|U )
echo "${Char}\c"
;;
esac
x=x+1
Char=`echo $string | cut -c ${x}-${x} `
done
echo

No RISK no FUN
Frank


Report Offensive Follow Up For Removal

Response Number 3
Name: LANkrypt0
Date: August 21, 2003 at 11:44:00 Pacific
Reply: (edit)

I have a bit of a different approach. Seems to work a bit faster, less memory intensive.

#!/bin/ksh
read string?"Enter a String: "
lcstring=$(print $string | tr "[:upper:]" "[:lower:]")
print $lcstring | tr "a" "A" | tr "e" "E" | tr "i" "I" | tr "o" "O" | tr "u" "U" | tr -d "[:lower:]"

Its only 3 lines so you have:
read ....
lcstring ....
then the last line is
print ....

You COULD make it two lines, but the second line would be humongous. You can also make it a few more lines, but, IMHO, this should be ok.


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 2 Days.
Discuss in The Lounge
Poll History




Data Recovery Software