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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

shell script for string search

Reply to Message Icon

Name: Bjorn
Date: August 20, 2003 at 10:54:57 Pacific
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.




Sponsored Link
Ads by Google

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

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


0

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

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


0

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

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







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


Sponsored links

Ads by Google


Results for: shell script for string search

shell script for string encryption www.computing.net/answers/unix/shell-script-for-string-encryption/7406.html

shell script for sent e-mail www.computing.net/answers/unix/shell-script-for-sent-email/5000.html

Shell Scripts for Recursive Search www.computing.net/answers/unix/shell-scripts-for-recursive-search/4070.html